Selaa lähdekoodia

Changes for the blog:
* Pager removed.
* Improved code readability.
* Posting a comment donesn't manually increase version number (db triggers do).

Iñigo Valentin 9 vuotta sitten
vanhempi
sitoutus
e6f75c1def
8 muutettua tiedostoa jossa 565 lisäystä ja 453 poistoa
  1. 1 2
      .gitignore
  2. 138 102
      www/blog/buscar.php
  3. 21 21
      www/blog/comment.php
  4. 18 14
      www/blog/common/leftpanel.php
  5. 37 22
      www/blog/common/rightpanel.php
  6. 137 125
      www/blog/index.php
  7. 205 148
      www/blog/post.php
  8. 8 19
      www/functions.php

+ 1 - 2
.gitignore

@@ -22,9 +22,8 @@ www-admin/redirect_s.php
 
 #SQL data
 sql/dbusers.sql
-sql/rows-test.sql
-sql/rows.sql
 sql/*201*
+sql/*row*.sql
 
 #Passwords file
 www/.htpasswd

+ 138 - 102
www/blog/buscar.php

@@ -1,37 +1,37 @@
 <?php
     session_start();
-    $http_host = $_SERVER['HTTP_HOST'];
+    $http_host = $_SERVER["HTTP_HOST"];
     include("../functions.php");
     $con = startdb();
     $proto = getProtocol();
+    $server = "$server";
     
     //Language
     $lang = selectLanguage();
-    include("../lang/lang_" . $lang . ".php");
+    include("../lang/lang_$lang.php");
     
-    $cur_section = $lng['section_blog'];
+    $cur_section = $lng["section_blog"];
     
     //Search terms
-    $search_field = mysqli_real_escape_string($con, $_GET['where']);
-    $search_term = strtolower(mysqli_real_escape_string($con, $_GET['query']));
-    if ($search_field == '' || $search_term == ''){
-        header("Location: $proto$http_host/blog/");
+    $search_field = mysqli_real_escape_string($con, $_GET["where"]);
+    $search_term = strtolower(mysqli_real_escape_string($con, $_GET["query"]));
+    if ($search_field == "" || $search_term == ""){
+        header("Location: $server/blog/");
         exit(-1);
     }
     
     //Get matches
     switch ($search_field){
-        case $lng['search_field_all']:
+        case $lng["search_field_all"]:
             $q = mysqli_query($con, "SELECT id, permalink, title_$lang AS title, text_$lang AS text, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, dtime, comments FROM post WHERE lower(title_es) LIKE '%$search_term%' OR lower(text_es) LIKE '%$search_term%' OR id IN (SELECT post FROM post_tag WHERE lower(tag) LIKE '%$search_term%') ORDER BY dtime DESC;");
             break;
-        case $lng['search_field_tag']:
+        case $lng["search_field_tag"]:
             $q = mysqli_query($con, "SELECT id, permalink, title_$lang AS title, text_$lang AS text, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, dtime, comments FROM post WHERE id IN (SELECT post FROM post_tag WHERE tag like '$search_term') ORDER BY dtime DESC;");
             break;
         default:
-            header("Location: $proto$http_host/blog/");
+            header("Location: $server/blog/");
             exit(-1);
     }
-    
 ?>
 <!DOCTYPE html>
 <html>
@@ -39,21 +39,21 @@
         <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
         <meta charset="utf-8"/>
         <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
-        <title><?php echo $lng['blog_title'];?> - Gasteizko Margolariak</title>
-        <link rel="shortcut icon" href="<?php echo "$proto$http_host/img/logo/favicon.ico";?>">
+        <title><?=$lng["blog_title"]?> - Gasteizko Margolariak</title>
+        <link rel="shortcut icon" href="<?=$server?>/img/logo/favicon.ico">
         <!-- CSS files -->
         <style>
-            <?php 
-                include("../css/ui.css"); 
-                include("../css/blog.css");
-            ?>
+<?php 
+            include("../css/ui.css"); 
+            include("../css/blog.css");
+?>
         </style>
         <!-- CSS for mobile version -->
         <style media="(max-width : 990px)">
-            <?php 
-                include("../css/m/ui.css"); 
-                include("../css/m/blog.css");
-            ?>
+<?php 
+            include("../css/m/ui.css"); 
+            include("../css/m/blog.css");
+?>
         </style>
         <!-- Script files -->
         <script type="text/javascript">
@@ -63,100 +63,136 @@
             ?>
         </script>
         <!-- Meta tags -->
-        <link rel="canonical" href="<?php echo "$proto$http_host/blog"; ?>"/>
-        <link rel="author" href="<?php echo "$proto$http_host"; ?>"/>
-        <link rel="publisher" href="<?php echo "$proto$http_host"; ?>"/>
-        <meta name="description" content="<?php echo $lng['blog_descrption'];?>"/>
-        <meta property="og:title" content="<?php echo $lng['blog_title'];?> - Gasteizko Margolariak"/>
-        <meta property="og:url" content="<?php echo "$proto$http_host/blog"; ?>"/>
-        <meta property="og:description" content="<?php echo $lng['blog_description'];?>"/>
-        <meta property="og:image" content="<?php echo "$proto$http_host/img/logo/logo.png";?>"/>
-        <meta property="og:site_name" content="<?php echo $lng['index_title'];?>"/>
+        <link rel="canonical" href="<?=$server?>/blog"/>
+        <link rel="author" href="<?=$server?>"/>
+        <link rel="publisher" href="<?=$server?>"/>
+        <meta name="description" content="<?=$lng["blog_descrption"]?>"/>
+        <meta property="og:title" content="<?=$lng["blog_title"]?> - Gasteizko Margolariak"/>
+        <meta property="og:url" content="<?=$server?>/blog"/>
+        <meta property="og:description" content="<?=$lng["blog_description"]?>"/>
+        <meta property="og:image" content="<?=$server?>/img/logo/logo.png"/>
+        <meta property="og:site_name" content="<?=$lng["index_title"]?>"/>
         <meta property="og:type" content="website"/>
-        <meta property="og:locale" content="<?php echo $lang; ?>"/>
+        <meta property="og:locale" content="<?=$lang?>"/>
         <meta name="twitter:card" content="summary"/>
-        <meta name="twitter:title" content="<?php echo $lng['blog_title'];?> - Gasteizko Margolariak"/>
-        <meta name="twitter:description" content="<?php echo $lng['blog_description'];?>"/>
-        <meta name="twitter:image" content="<?php echo "$proto$http_host/img/logo/logo.png";?>"/>
-        <meta name="twitter:url" content="<?php echo"$proto$http_host"; ?>"/>
+        <meta name="twitter:title" content="<?=$lng["blog_title"]?> - Gasteizko Margolariak"/>
+        <meta name="twitter:description" content="<?=$lng["blog_description"]?>"/>
+        <meta name="twitter:image" content="<?=$server?>/img/logo/logo.png"/>
+        <meta name="twitter:url" content="<?=$server?>"/>
         <meta name="robots" content="no-index no-follow"/>
     </head>
     <body>
-        <?php include("../header.php"); ?>
+<?php
+        include("../header.php");
+?>
         <div id="content">
-            <?php include("common/leftpanel.php"); ?>
+<?=
+            include("common/leftpanel.php");
+?>
             <div id="middle_column">
                 <div class="section">
-                    <h3 class="section_title"><?php echo($lng['blog_search']);?></h3>
+                    <h3 class="section_title"><?=$lng["blog_search"])?></h3>
                     <div class="entry">
-                        <?php
-                            if (mysqli_num_rows($q) == 1){
-                                echo "$lng[blog_search_1]<span class='italic'>$search_term</span>&nbsp: " . strval(mysqli_num_rows($q)) . $lng['blog_search_result'];
-                            }
-                            else{
-                                echo "$lng[blog_search_1]<span class='italic'>$search_term</span>&nbsp: " . strval(mysqli_num_rows($q)) . $lng['blog_search_results'];
-                            }
-                        ?>
-                    </div>
-                    <?php
-                        while($r = mysqli_fetch_array($q)){
-                            echo "<div itemscope itemtype='http://schema.org/BlogPosting' class='entry blog_entry'>\n";
-                            echo "<meta itemprop='inLanguage' content='$lang'/>\n";
-                            echo "<meta itemprop='datePublished dateModified' content='$r[isodate]'/>\n";
-                            echo "<meta itemprop='headline name' content='$r[title]'/>\n";
-                            echo "<meta itemprop='articleBody text' content='$r[text]'/>\n";
-                            echo "<meta itemprop='mainEntityOfPage' content='$proto$http_host'/>\n";
-                            echo "<div class='hidden' itemprop='author publisher' itemscope itemtype='http://schema.org/Organization'>\n";
-                            echo "<meta itemprop='legalName' content='Asociaci&oacute;n Cultural Recreativa Gasteizko Margolariak'/>\n";
-                            echo "<meta itemprop='name' content='Gasteizko Margolariak'/>\n";
-                            echo "<meta itemprop='logo' content='$proto$http_host/img/logo/logo.png'/>\n";
-                            echo "<meta itemprop='foundingDate' content='03-02-2013'/>\n";
-                            echo "<meta itemprop='telephone' content='+34637140371'/>\n";
-                            echo "<meta itemprop='url' content='$proto$http_host'/>\n";
-                            echo "</div>\n";
-                            echo "<h3 class='entry_title post_search_title'><a itemprop='url' href='$proto$http_host/blog/$r[permalink]'>$r[title]</a></h2>\n";
-                            # Tags (if any) and date
-                            echo "<table class='post_footer post_footer_search'><tr>\n";
-                            $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post= $r[id];");
-                            if (mysqli_num_rows($q_tag) > 0){
-                                $tag_string = "<span class='tags desktop'>Tags: ";
-                                $tag_raw = "";
-                                while ($r_tag = mysqli_fetch_array($q_tag)){
-                                    $tag_string = $tag_string . "<a href='$proto$http_host/blog/buscar/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
-                                    $tag_raw = $tag_raw . "$r_tag[tag],";
-                                }
-                                $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
-                                $tag_string = $tag_string . "</span>";
-                                $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
-                                echo "<meta itemprop='keywords' content='$tag_raw'/>\n";
-                                echo "<td><span class='date'>" . formatDate($r['dtime'], $lang, false) . "</span>&nbsp;&nbsp;&nbsp;$tag_string</td>\n";
-                            }
-                            else{
-                                echo "<td><span class='date'></span>" . formatDate($r['dtime'], $lang) . "</span></td>\n";
-                            }
-                            echo "</tr></table><hr class='post_search_separator'/>\n";
+<?php
+                        if (mysqli_num_rows($q) == 1){
+?>
+                            <?=$lng["blog_search_1"]?>
+                            <span class='italic'><?=$search_term?></span>
+                            &nbsp: <?=strval(mysqli_num_rows($q))?> <?=$lng["blog_search_result"]?>
+<?php
+                        }
+                        else{
+?>
+                            <?=$lng["blog_search_1"]?>
+                            <span class='italic'><?=$search_term?></span>
+                            &nbsp: <?=strval(mysqli_num_rows($q))?> <?=$lng["blog_search_results"]?>
+<?php
+                        }
+?>
+                    </div> <!-- .entry -->
+<?php
+                    while($r = mysqli_fetch_array($q)){
+?>
+                        <div itemscope itemtype='http://schema.org/BlogPosting' class='entry blog_entry'>
+                            <meta itemprop='inLanguage' content='$lang'/>
+                            <meta itemprop='datePublished dateModified' content='<?=$r["isodate"]?>'/>
+                            <meta itemprop='headline name' content='<?=$r["title"]?>'/>
+                            <meta itemprop='articleBody text' content='<?=$r["text"]?>'/>
+                            <meta itemprop='mainEntityOfPage' content='<?=$server?>'/>
+                            <div class='hidden' itemprop='author publisher' itemscope itemtype='http://schema.org/Organization'>
+                                <meta itemprop='legalName' content='Asociaci&oacute;n Cultural Recreativa Gasteizko Margolariak'/>
+                                <meta itemprop='name' content='Gasteizko Margolariak'/>
+                                <meta itemprop='logo' content='<?=$server?>/img/logo/logo.png'/>
+                                <meta itemprop='foundingDate' content='03-02-2013'/>
+                                <meta itemprop='telephone' content='+34637140371'/>
+                                <meta itemprop='url' content='<?=$server?>'/>
+                            </div>
+                            <h3 class='entry_title post_search_title'>
+                                <a itemprop='url' href='<?=$server?>/blog/<?=$r["permalink"]?>'><?=$r["title"]?></a>
+                            </h3>
+                            <table class='post_footer post_footer_search'>
+                                <tr>
+<?php
+                                    # Tags (if any) and date
+                                    $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post= $r[id];");
+                                    if (mysqli_num_rows($q_tag) > 0){
+                                        $tag_string = "<span class='tags desktop'>Tags: ";
+                                        $tag_raw = "";
+                                        while ($r_tag = mysqli_fetch_array($q_tag)){
+                                            $tag_string = $tag_string . "<a href='$server/blog/buscar/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
+                                            $tag_raw = $tag_raw . "$r_tag[tag],";
+                                        }
+                                        $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
+                                        $tag_string = $tag_string . "</span>";
+                                        $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
+?>
+                                        <meta itemprop='keywords' content='<?=$tag_raw?>'/>
+                                        <td>
+                                            <span class='date'><?=formatDate($r["dtime"], $lang, false)?></span>
+                                            &nbsp;&nbsp;&nbsp;<?=$tag_string?>
+                                        </td>
+<?php
+                                    }
+                                    else{
+?>
+                                        <td>
+                                            <span class='date'><?=formatDate($r["dtime"], $lang)?></span>
+                                        </td>
+<?php
+                                    }
+?>
+                                </tr>
+                            </table> <!-- .post_footer_search -->
+                            <hr class='post_search_separator'/>
+<?php
                             #Image and text
                             $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $r[id] ORDER BY idx LIMIT 1;");
                             if (mysqli_num_rows($q_image) > 0){
                                 $r_image = mysqli_fetch_array($q_image);
-                                echo "<a href='$proto$http_host/blog/$r[permalink]'>\n";
-                                echo "<meta itemprop='image' content='$proto$http_host/img/blog/$r_image[image]'/>\n";
-                                echo "<img class='post_search_image alt='$r[title]' src='$proto$http_host/img/blog/preview/$r_image[image]'/>\n";
-                                echo "</a>\n";
+?>
+                                <a href='<?=$server?>/blog/<?=$r["permalink"]?>'>
+                                    <meta itemprop='image' content='<?=$server?>/img/blog/<?=$r_image["image"]?>'/>
+                                    <img class='post_search_image alt='<?=$r["title"]?>' src='<?=$server?>/img/blog/preview/<?=$r_image["image"]?>'/>
+                                </a>
+<?php
                             }
-                            echo "<p class='post_search_text'>" . cutText($r['text'], 150, $lng['blog_read_more'], "$proto$http_host/blog/$r[permalink]/") . "</p>\n";
-                            echo "<br/>\n";
-                            echo "</div>\n";
-                        }
-                    ?>
-                </div>
-            </div>
-            <?php include("common/rightpanel.php"); ?>
-        </div>
-        <?php
-            include("../footer.php");
-            $ad = ad($con, $lang, $lng); 
-            stats($ad, $ad_static, "blog", "");
-        ?>
+?>
+                            <p class='post_search_text'><?=cutText($r["text"], 150, $lng["blog_read_more"], "$server/blog/$r[permalink]/")?></p>
+                            <br/>
+                        </div> <!-- .blog_entry-->
+<?php
+                    } //  while($r = mysqli_fetch_array($q))
+?>
+                </div> <!-- .section -->
+            </div> <!-- #middle_column -->
+<?php
+            include("common/rightpanel.php");
+?>
+        </div> <!-- #content -->
+<?php
+        include("../footer.php");
+        $ad = ad($con, $lang, $lng); 
+        stats($ad, $ad_static, "blog", "");
+?>
     </body>
 </html>

+ 21 - 21
www/blog/comment.php

@@ -1,9 +1,11 @@
 <?php
-    
-    $http_host = $_SERVER['HTTP_HOST'];
+
+    $http_host = $_SERVER["HTTP_HOST"];
     include("../functions.php");
-    $con = startdb('rw');
-    
+    $con = startdb("rw");
+    $proto = getProtocol();
+    $server = "$proto$http_host";
+
     //Get post values
     $from =mysqli_real_escape_string($con, $_POST["from"]);
     $post = mysqli_real_escape_string($con, $_POST["post"]);
@@ -19,52 +21,50 @@
         http_response_code(405);
         exit(-1);
     }
-    
+
     //Check language, set fallback.
     if ($lang != 'es' && $lang != 'en' && $lang != 'eu'){
         $lang = 'es';
     }
-    
+
     //Chack for null fields
     if (strlen($user) <= 0 || strlen($text) <= 0){
         error_log("Tried to post a comment with null text or user on post. USER: '$user', TEXT: '$text'");
         http_response_code(405);
         exit(-1);
     }
-    
+
     if ($from == 'web'){
         //Format newlines in text
         $text = str_replace(["\r\n", "\r", "\n"], "<br/>", $text);
-        
+
         //Get visit
         $ip = getUserIP();
         $visit = '';
         $q = mysqli_query($con, "SELECT id FROM stat_visit WHERE ip = '$ip';");
         if (mysqli_num_rows($q) > 0){
             $r = mysqli_fetch_array($q);
-            $visit = $r['id'];
+            $visit = $r["id"];
         }
-        
+
         //Insert row
         mysqli_query($con, "INSERT INTO post_comment (post, text, username, lang, visit) VALUES ($post, '$text', '$user', '$lang', '$visit');");
-        version();
     }
     elseif ($from == 'app'){
         $code = mysqli_real_escape_string($con, $_POST["code"]);
         mysqli_query($con, "INSERT INTO post_comment (post, text, username, lang, app) VALUES ($post, '$text', '$user', '$lang', '$code');");
-        version();
     }
-    
+
     //Prepare the page to update the comment section
-    //WARNING: If changes are done here, do the same in post.php
     $q_comment = mysqli_query($con, "SELECT id, post, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, dtime, user, username, lang, text FROM post_comment WHERE post = $post AND approved = 1 ORDER BY dtime;");
     while ($r_comment = mysqli_fetch_array($q_comment)){
-        echo "<div itemprop='comment' itemscope itemtype='http://schema.org/UserComments' id='comment_$r_comment[id]' class='comment'>\n";
-        //When official users are implementes, see if there is user or username
-        echo "<span itemprop='creator' class='comment_user'>$r_comment[username]</span>\n";
-        echo "<span class='comment_date date'><meta itemprop='commentTime' content='$r_comment[isodate]'/>" . formatDate($r_comment['dtime'], $lang) . "</span>\n";
-        echo "<p itemprop='commentText' class='comment_text'>$r_comment[text]</p>";
-        echo "<hr class='comment_line'/>\n";
-        echo "</div>\n";
+?>
+        <div itemprop='comment' itemscope itemtype='http://schema.org/UserComments' id='comment_<?=$r_comment["id"]?>' class='comment'>
+            <span itemprop='creator' class='comment_user'><?=$r_comment["username"]?></span>
+            <span class='comment_date date'><meta itemprop='commentTime' content='<?=$r_comment["isodate"]?>'/><?=formatDate(<?=$r_comment["dtime"], $lang)?></span>
+            <p itemprop='commentText' class='comment_text'><?=$r_comment["text"]?></p>
+            <hr class='comment_line'/>
+        </div>
+<?php
     }
 ?>

+ 18 - 14
www/blog/common/leftpanel.php

@@ -1,27 +1,31 @@
-<div id="left_column">
-    <div id="search_panel" class="section">
-        <h3 id="search_panel_header" class="section_title search_element no_mobile"><?php echo $lng['blog_search'];?></h3>
-        <div class="entry" id="search_panel_inputs">
-            <form action="#" onSubmit="event.preventDefault();launchSearch('<?php echo $lng['search_field_all']; ?>');">
-                <input id="search_panel_input" class="search_element" type="text" name="query" placeholder="<?php echo($lng['blog_search']); ?>"/>
-                <input id="search_panel_submit" class="search_element" type="submit" value="<?php echo $lng['blog_search'];?>"/>
+<div id='left_column'>
+    <div id='search_panel' class='section'>
+        <h3 id='search_panel_header' class='section_title search_element no_mobile'><?=$lng["blog_search"]?></h3>
+        <div class='entry' id='search_panel_inputs'>
+            <form action='#' onSubmit='event.preventDefault();launchSearch("<?=$lng["search_field_all"]?>");'>
+                <input id='search_panel_input' class='search_element' type='text' name='query' placeholder='<?=$lng["blog_search"]?>'/>
+                <input id='search_panel_submit' class='search_element' type='submit' value='<?=$lng["blog_search"]?>'/>
             </form>
         </div>
     </div>
-    <div id="tag_cloud" class="section desktop">
-        <h3 class="section_title"><?php echo $lng['blog_tag_cloud'];?></h3>
-        <div class="entry">
+    <div id='tag_cloud' class='section desktop'>
+        <h3 class='section_title'><?=$lng["blog_tag_cloud"]?></h3>
+        <div class='entry'>
             <?php
                 //Get the most used tag
                 $q_max = mysqli_query($con, "SELECT max(count) AS max FROM (SELECT count(post) AS count FROM post_tag GROUP BY tag) AS t;");
                 $r_max = mysqli_fetch_array($q_max);
-                $max = $r_max['max'];
+                $max = $r_max["max"];
                 $q_tag = mysqli_query($con, "SELECT tag, count(post) AS count FROM post_tag GROUP BY tag;");
                 while($r_tag = mysqli_fetch_array($q_tag)){
-                    $size = round(60 + 100 * $r_tag['count'] / $max);    //TEST: Relativize
-                    echo "<a href='$proto$http_host/blog/buscar/tag/$r_tag[tag]'><span style='font-size: $size%'>$r_tag[tag]</span></a>\n";
+                    $size = round(60 + 100 * $r_tag['count'] / $max);
+?>
+                    <a href='<?=$server?>/blog/buscar/tag/<?=$r_tag["tag"]?>'>
+                        <span style='font-size: <?=$size?>%'><?=$r_tag["tag"]?></span>
+                    </a>
+<?php
                 }
-            ?>
+?>
         </div>
     </div>
 </div>

+ 37 - 22
www/blog/common/rightpanel.php

@@ -1,28 +1,43 @@
 <div id="right_column">
     <div id="archive" class="section desktop">
-        <h3 class="section_title"><?php echo $lng['blog_archive']; ?></h3>
+        <h3 class="section_title"><?=$lng["blog_archive"]?></h3>
         <div class='entry'>
-            <?php
-                $q_year = mysqli_query($con, "SELECT year(dtime) AS year FROM post WHERE visible = 1 GROUP BY year(dtime) ORDER BY year DESC;");
-                while($r_year = mysqli_fetch_array($q_year)){
-                    echo "<div class='year pointer' onClick=\"toggleElement('year_$r_year[year]');\">";
-                    echo ("<img class='slid' id='slid_year_$r_year[year]' src='$proto$http_host/img/misc/slid-right.png' alt=' '/><span class='fake_a'>$r_year[year]</span>");
-                    echo "</div>\n";
-                    echo "<div class='list_year pointer' id='list_year_$r_year[year]'>\n";
+<?php
+            $q_year = mysqli_query($con, "SELECT year(dtime) AS year FROM post WHERE visible = 1 GROUP BY year(dtime) ORDER BY year DESC;");
+            while($r_year = mysqli_fetch_array($q_year)){
+?>
+                <div class='year pointer' onClick='toggleElement("year_<?=$r_year["year"]?>");'>
+                    <img class='slid' id='slid_year_<?=$r_year["year"]?>' src='<?=$server?>/img/misc/slid-right.png' alt='<?=$r_year["year"]?>'/>
+                    <span class='fake_a'><?=$r_year["year"]?></span>
+                </div>
+                <div class='list_year pointer' id='list_year_<?=$r_year["year"]?>'>
+<?php
                     $q_month = mysqli_query($con, "SELECT month(dtime) AS month FROM post WHERE visible = 1 AND year(dtime) = $r_year[year] GROUP BY month(dtime) ORDER BY month DESC;");
                     while($r_month = mysqli_fetch_array($q_month)){
-                        echo "<div class='month pointer' onClick=\"toggleElement('month_$r_year[year]_$r_month[month]');\">";
-                        echo ("<img class='slid' id='slid_month_$r_year[year]_$r_month[month]' src='$proto$http_host/img/misc/slid-right.png' alt=' '/><span class='fake_a'>" . $lng['months'][$r_month['month'] - 1] . "</span>");
-                        echo "</div>\n";
-                        echo "<ul id='list_month_$r_year[year]_$r_month[month]' class='post_list'>\n";
-                        $q_title = mysqli_query($con, "SELECT id, permalink, title_$lang AS title FROM post WHERE visible = 1 AND year(dtime) = $r_year[year] AND month(dtime) = '$r_month[month]' ORDER BY dtime DESC;");
-                        while($r_title = mysqli_fetch_array($q_title))
-                            echo "<li><a href='$proto$http_host/blog/" . $r_title['permalink']  . "'>$r_title[title]</a></li>\n";
-                        echo "</ul>\n";
+?>
+                        <div class='month pointer' onClick='toggleElement("month_<?=$r_year["year"]?>_<?=$r_month["month"]?>");'>
+                            <img class='slid' id='slid_month_<?=$r_year["year"]?>_<?=$r_month["month"]?>' src='<?=$server?>?/img/misc/slid-right.png' alt='<?=$r_month["month"]?>'/>
+                            <span class='fake_a'><?=$lng["months"][$r_month["month"] - 1]?></span>
+                        </div>
+                        <ul id='list_month_<?=$r_year["year"]?>_<?=$r_month["month"]?>' class='post_list'>
+<?php
+                            $q_title = mysqli_query($con, "SELECT id, permalink, title_$lang AS title FROM post WHERE visible = 1 AND year(dtime) = $r_year[year] AND month(dtime) = '$r_month[month]' ORDER BY dtime DESC;");
+                            while($r_title = mysqli_fetch_array($q_title)){
+?>
+                                <li>
+                                    <a href='$proto$http_host/blog/<?=$r_title["permalink"]?>'><?=$r_title["title"]?></a>
+                                </li>
+<?php
+                            }
+?>
+                        </ul>
+<?php
                     }
-                    echo "</div>\n";
-                }
-            ?>
-        </div>
-    </div>
-</div>
+?>
+                </div> <!-- #list_year_<?=$r_year["year"]?> -->
+<?php
+            } //while($r_year = mysqli_fetch_array($q_year))
+?>
+        </div> <!-- .entry -->
+    </div> <!-- #archive -->
+</div> <!-- #right_column-->

+ 137 - 125
www/blog/index.php

@@ -4,12 +4,13 @@
     include("../functions.php");
     $con = startdb();
     $proto = getProtocol();
-    
+    $server = "$proto$http_host";
+
     //Language
     $lang = selectLanguage();
-    include("../lang/lang_" . $lang . ".php");
-    
-    $cur_section = $lng['section_blog'];
+    include("../lang/lang_$lang.php");
+
+    $cur_section = $lng["section_blog"];
 ?>
 <!DOCTYPE html>
 <html>
@@ -17,152 +18,163 @@
         <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
         <meta charset="utf-8"/>
         <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
-        <title><?php echo $lng['blog_title'];?> - Gasteizko Margolariak</title>
-        <link rel="shortcut icon" href="<?php echo "$proto$http_host/img/logo/favicon.ico";?>">
+        <title><?=$lng["blog_title"];?> - Gasteizko Margolariak</title>
+        <link rel="shortcut icon" href="<?=$server?>/img/logo/favicon.ico">
         <!-- CSS files -->
         <style>
-            <?php 
-                include("../css/ui.css"); 
-                include("../css/blog.css");
-            ?>
+<?php
+            include("../css/ui.css");
+            include("../css/blog.css");
+?>
         </style>
         <!-- CSS for mobile version -->
         <style media="(max-width : 990px)">
-            <?php 
-                include("../css/m/ui.css"); 
-                include("../css/m/blog.css");
-            ?>
+<?php
+            include("../css/m/ui.css"); 
+            include("../css/m/blog.css");
+?>
         </style>
         <!-- Script files -->
         <script type="text/javascript">
-            <?php
+<?php
                 include("../script/ui.js");
                 include("../script/blog.js");
-            ?>
+?>
         </script>
         <!-- Meta tags -->
-        <link rel="canonical" href="<?php echo "$proto$http_host/blog"; ?>"/>
-        <link rel="author" href="<?php echo "$proto$http_host"; ?>"/>
-        <link rel="publisher" href="<?php echo "$proto$http_host"; ?>"/>
-        <meta name="description" content="<?php echo $lng['blog_descrption'];?>"/>
-        <meta property="og:title" content="<?php echo $lng['blog_title'];?> - Gasteizko Margolariak"/>
-        <meta property="og:url" content="<?php echo "$proto$http_host/blog"; ?>"/>
-        <meta property="og:description" content="<?php echo $lng['blog_description'];?>"/>
-        <meta property="og:image" content="<?php echo "$proto$http_host/img/logo/logo.png";?>"/>
-        <meta property="og:site_name" content="<?php echo $lng['index_title'];?>"/>
+        <link rel="canonical" href="<?=$server?>/blog/">
+        <link rel="author" href="<?=$server?>"/>
+        <link rel="publisher" href="<?=$server?>"/>
+        <meta name="description" content="<?=$lng["blog_descrption"]?>"/>
+        <meta property="og:title" content="<?=$lng["blog_title"]?> - Gasteizko Margolariak"/>
+        <meta property="og:url" content="<?=$server?>/blog/">
+        <meta property="og:description" content="<?=$lng["blog_description"]?>"/>
+        <meta property="og:image" content="<?=$server?>/img/logo/logo.png";?>"/>
+        <meta property="og:site_name" content="<?=$lng["index_title"]?>"/>
         <meta property="og:type" content="website"/>
         <meta property="og:locale" content="<?php echo $lang; ?>"/>
         <meta name="twitter:card" content="summary"/>
-        <meta name="twitter:title" content="<?php echo $lng['blog_title'];?> - Gasteizko Margolariak"/>
-        <meta name="twitter:description" content="<?php echo $lng['blog_description'];?>"/>
-        <meta name="twitter:image" content="<?php echo "$proto$http_host/img/logo/logo.png";?>"/>
-        <meta name="twitter:url" content="<?php echo"$proto$http_host"; ?>"/>
+        <meta name="twitter:title" content="<?=$lng["blog_title"]?> - Gasteizko Margolariak"/>
+        <meta name="twitter:description" content="<?=$lng["blog_description"]?>"/>
+        <meta name="twitter:image" content="<?=$server?>/img/logo/logo.png";?>"/>
+        <meta name="twitter:url" content="<?=$server?>"/>
         <meta name="robots" content="index follow"/>
     </head>
     <body>
-        <?php include("../header.php"); ?>
+<?php include("../header.php"); ?>
         <div id="content">
-            <?php include("common/leftpanel.php"); ?>
+<?php include("common/leftpanel.php"); ?>
             <div id="middle_column" class="section">
-                <?php
-                    echo("<h3 class='section_title'>$lng[section_blog]</h3>\n");
-                    $offset = (int) $_GET['o'];
-                    $q = mysqli_query($con, "SELECT id, permalink, title_$lang AS title, text_$lang AS text, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, dtime, comments FROM post WHERE visible = 1 ORDER BY dtime DESC LIMIT 5 OFFSET $offset;");
+                <h3 class='section_title'><?=$lng["section_blog"]?></h3>
+<?php
+                    $q = mysqli_query($con, "SELECT id, permalink, title_$lang AS title, text_$lang AS text, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, dtime, comments FROM post WHERE visible = 1 ORDER BY dtime DESC;");
                     while($r = mysqli_fetch_array($q)){
-                        echo "<div itemscope itemtype='http://schema.org/BlogPosting' class='entry blog_entry'>\n";
-                        echo "<meta itemprop='inLanguage' content='$lang'/>\n";
-                        echo "<meta itemprop='datePublished dateModified' content='$r[isodate]'/>\n";
-                        echo "<meta itemprop='headline name' content='$r[title]'/>\n";
-                        echo "<meta itemprop='articleBody text' content='$r[text]'/>\n";
-                        echo "<meta itemprop='mainEntityOfPage' content='$proto$http_host'/>\n";
-                        echo "<div class='hidden' itemprop='author publisher' itemscope itemtype='http://schema.org/Organization'>\n";
-                        echo "<meta itemprop='legalName' content='Asociaci&oacute;n Cultural Recreativa Gasteizko Margolariak'/>\n";
-                        echo "<meta itemprop='name' content='Gasteizko Margolariak'/>\n";
-                        echo "<meta itemprop='logo' content='$proto$http_host/img/logo/logo.png'/>\n";
-                        echo "<meta itemprop='foundingDate' content='03-02-2013'/>\n";
-                        echo "<meta itemprop='telephone' content='+34637140371'/>\n";
-                        echo "<meta itemprop='url' content='$proto$http_host'/>\n";
-                        echo "</div>\n";
-                        echo "<h3 class='entry_title'><a itemprop='url' href='$proto$http_host/blog/$r[permalink]'>$r[title]</a></h2>\n";
-                        $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $r[id] ORDER BY idx LIMIT 1;");
-                        if (mysqli_num_rows($q_image) > 0){
-                            $r_image = mysqli_fetch_array($q_image);
-                            echo "<div class='post_list_image_container'>\n";
-                            echo "<a href='$proto$http_host/blog/$r[permalink]'>\n";
-                            echo "<meta itemprop='image' content='$proto$http_host/img/blog/view/$r_image[image]'/>\n";
-                            echo "<img class='post_list_image alt='$r[title]' src='$proto$http_host/img/blog/miniature/$r_image[image]'/>\n";
-                            echo "</a>\n";
-                            echo "</div>\n";
-                        }
-                        echo "<p>" . cutText($r['text'], 800, $lng['blog_read_more'], "$proto$http_host/blog/$r[permalink]/") . "</p>\n";
-                        # Tags (if any), date, and comment counter
-                        echo "<hr><table class='post_footer'><tr>\n";
-                        $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post= $r[id];");
-                        if (mysqli_num_rows($q_tag) > 0){
-                            $tag_string = "<span class='tags desktop'>Tags: ";
-                            $tag_raw = "";
-                            while ($r_tag = mysqli_fetch_array($q_tag)){
-                                $tag_string = $tag_string . "<a href='$proto$http_host/blog/buscar/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
-                                $tag_raw = $tag_raw . "$r_tag[tag],";
+?>
+                        <div itemscope itemtype='http://schema.org/BlogPosting' class='entry blog_entry'>
+                            <meta itemprop='inLanguage' content='<?=$lang?>'/>
+                            <meta itemprop='datePublished dateModified' content='<?=$r["isodate"]?>'/>
+                            <meta itemprop='headline name' content='$<?=r["title"]?>'/>
+                            <meta itemprop='articleBody text' content='<?=$r["text"]?>'/>
+                            <meta itemprop='mainEntityOfPage' content='<?=$server?>'/>
+                            <div class='hidden' itemprop='author publisher' itemscope itemtype='http://schema.org/Organization'>
+                                <meta itemprop='legalName' content='Asociaci&oacute;n Cultural Recreativa Gasteizko Margolariak'/>
+                                <meta itemprop='name' content='Gasteizko Margolariak'/>
+                                <meta itemprop='logo' content='<?=$server?>/img/logo/logo.png'/>
+                                <meta itemprop='foundingDate' content='03-02-2013'/>
+                                <meta itemprop='telephone' content='+34637140371'/>
+                                <meta itemprop='url' content='<?=$server?>'/>
+                            </div>
+                            <h3 class='entry_title'><a itemprop='url' href='<?=$server?>/blog/<?=$r["permalink"]?>'><?=$r["title"]?></a></h3>
+<?php
+                            $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $r[id] ORDER BY idx LIMIT 1;");
+                            if (mysqli_num_rows($q_image) > 0){
+                                $r_image = mysqli_fetch_array($q_image);
+?>
+                                <div class='post_list_image_container'>
+                                    <a href='<?=$server?>/blog/<?=$r["permalink"]?>'>
+                                        <meta itemprop='image' content='<?=$server?>/img/blog/view/<?=$r_image["image"]?>'/>
+                                        <img class='post_list_image alt='<?=$r["title"]?>' src='<?=$server?>/img/blog/miniature/<?=$r_image["image"]?>'/>
+                                    </a>
+                                </div>
+<?php
                             }
-                            $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
-                            $tag_string = $tag_string . "</span>";
-                            $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
-                            echo "<meta itemprop='keywords' content='$tag_raw'/>\n";
-                            echo "<td><span class='date'>" . formatDate($r['dtime'], $lang, false) . "</span>&nbsp;&nbsp;&nbsp;$tag_string</td>\n";
-                        }
-                        else
-                            echo "<td><span class='date'>" . formatDate($r['dtime'], $lang, false) . "</span></td>\n";
-                        #Comment counter
-                        if ($r['comments'] == 1){
-                            $q_comment = mysqli_query($con, "SELECT count(id) AS count FROM post_comment WHERE post = $r[id] AND visible = 1;");
-                            $r_comment = mysqli_fetch_array($q_comment);
-                            echo "<meta itemprop='commentCount interationCount' content='$r_comment[count]'/>\n";
-                            if ($r_comment['count'] == 1)
-                                echo "<td class='r_comment'><span class='comment_counter'>1 $lng[blog_comments_1]</span>\n";
-                            else if ($r_comment['count'] == 0)
-                                echo "<td class='r_comment'><span class='comment_counter'>$lng[blog_comments_0]</span>\n";
-                            else 
-                                echo "<td class='r_comment'><span class='comment_counter'>$r_comment[count] $lng[blog_comments_multiple]</span>\n";
-                        }
-                        echo "</td>\n";
-                        echo "</tr></table>\n";
-                        echo "</div></br>\n";
-                    }
-                    #Pager
-                    $q_count = mysqli_query($con, "SELECT COUNT(id) AS count FROM post WHERE visible = 1;");
-                    $r_count = mysqli_fetch_array($q_count);
-                    $cur_page = (int) ($offset / 5) + 1;
-                    $max_page = (int) ($r_count['count'] / 5);
-                    if ($r_count['count'] % 5 != 0)
-                        $max_page ++;
-                    echo "<div id='pager'><table id='pager'><tr>\n";
-                    if ($cur_page > 4){
-                        echo "<td><div class='entry'><a href='$proto$http_host/blog/0'>1</a></div></td><td class='pager_ellipse'><div class='entry'>...</div></td>\n";
-                        for ($i = $cur_page - 2; $i < $cur_page; $i ++)
-                            echo "<td><div class='entry'><a href='$proto$http_host/blog/" . (5 * $i - 5) . "'>" . $i . "</a></div></td>\n";
-                    }
-                    else
-                        for ($i = 1; $i < $cur_page; $i ++)
-                            echo "<td><div class='entry'><a href='$proto$http_host/blog/" . (5 * $i - 5) . "'>" . $i . "</a></div></td>\n";
-                    echo "<td class='pager_current'><div class='entry'>$cur_page</div></td>\n";
-                    if ($cur_page + 4 < $max_page){
-                        for ($i = $cur_page + 1; $i < $cur_page + 3; $i ++)
-                            echo "<td><div class='entry'><a href='$proto$http_host/blog/" . (5 * $i - 5) . "'>" . $i . "</div></a></td>";
-                        echo "<td class='pager_ellipse'><div class='entry'>...</div></td><td><div class='entry'><a href='/blog/" . ($max_page * 5 - 5) . "'>$max_page</a></div></td>";
-                    }
-                    else
-                        for ($i = $cur_page + 1; $i <= $max_page; $i ++)
-                            echo "<td><div class='entry'><a href='$proto$http_host/blog/" . (5 * $i - 5) . "'>" . $i . "</a></div></td>";
-                    echo "</tr></table></div>\n";
-                ?>
-            </div>
-            <?php include("common/rightpanel.php"); ?>
+?>
+                            <p><?=cutText($r["text"], 800, $lng["blog_read_more"], "$server/blog/$r[permalink]/")?></p>
+
+                            <hr/>
+                            <table class='post_footer'>
+                                <tr>
+<?php
+                                    // Tags (if any), date, and comment counter
+                                    $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post= $r[id];");
+                                    if (mysqli_num_rows($q_tag) > 0){
+                                        $tag_string = "<span class='tags desktop'>Tags: ";
+                                        $tag_raw = "";
+                                        while ($r_tag = mysqli_fetch_array($q_tag)){
+                                            $tag_string = $tag_string . "<a href='$proto$http_host/blog/buscar/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
+                                            $tag_raw = $tag_raw . "$r_tag[tag],";
+                                        }
+                                        $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
+                                        $tag_string = $tag_string . "</span>";
+                                        $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
+?>
+                                        <meta itemprop='keywords' content='<?=$tag_raw?>'/>
+                                        <td>
+                                            <span class='date'><?=formatDate($r["dtime"], $lang, false)?></span>&nbsp;&nbsp;&nbsp;<?=$tag_string?>
+                                        </td>
+<?php
+                                    }
+                                    else{
+?>
+                                        <td>
+                                            <span class='date'><?=formatDate($r['dtime'], $lang, false)?></span>
+                                        </td>
+<?php
+                                    }
+                                    #Comment counter
+                                    if ($r["comments"] == 1){
+                                        $q_comment = mysqli_query($con, "SELECT count(id) AS count FROM post_comment WHERE post = $r[id] AND visible = 1;");
+                                        $r_comment = mysqli_fetch_array($q_comment);
+?>
+                                        <meta itemprop='commentCount interationCount' content='<?=$r_comment["count"]?>'/>
+                                        <td class='r_comment'>
+<?php
+                                            if ($r_comment['count'] == 1){
+?>
+                                                <span class='comment_counter'>1 <?=$lng["blog_comments_1"]?></span>
+<?php
+                                            }
+                                            else if ($r_comment['count'] == 0){
+?>
+                                                <span class='comment_counter'><?=$lng["blog_comments_0"]?></span>
+<?php
+                                            }
+                                            else{
+?>
+                                                <span class='comment_counter'>$<?=r_comment["count"]?> <?=$lng["blog_comments_multiple"]?></span>
+<?php
+                                            }
+?>
+                                        </td>
+<?php
+                                    }if ($r["comments"] == 1)
+?>
+                                </tr>
+                            </table> <!-- .post_footer -->
+                        </div> <!-- .blog_entry -->
+                        </br>
+<?php
+                    } // while($r = mysqli_fetch_array($q))
+?>
+            </div> <!-- .section -->
+<?php
+            include("common/rightpanel.php");
+?>
         </div>
-        <?php
+<?php
             include("../footer.php");
             $ad = ad($con, $lang, $lng); 
             stats($ad, $ad_static, "blog", "");
-        ?>
+?>
     </body>
 </html>

+ 205 - 148
www/blog/post.php

@@ -1,212 +1,269 @@
 <?php
-    $http_host = $_SERVER['HTTP_HOST'];
+    $http_host = $_SERVER["HTTP_HOST"];
     include("../functions.php");
     $con = startdb();
     $proto = getProtocol();
+    $server = "$proto$http_host";
     
     //Language
     $lang = selectLanguage();
-    include("../lang/lang_" . $lang . ".php");
+    include("../lang/lang_$lang.php");
     
-    $cur_section = $lng['section_blog'];
+    $cur_section = $lng["section_blog"];
     
     // Get current post id. Redirect if inexistent or invisible
-    $perm = mysqli_real_escape_string($con, $_GET['perm']);
+    $perm = mysqli_real_escape_string($con, $_GET["perm"]);
     $q = mysqli_query($con, "SELECT id, permalink, title_$lang AS title, text_$lang AS text, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, DATE_FORMAT(dtime,'%b %d, %Y T%T') as dtime, comments FROM post WHERE permalink = '$perm' AND visible = 1;");
     if (mysqli_num_rows($q) == 0){
-        header("Location: $proto$http_host/blog/");
+        header("Location: $server/blog/");
         exit(-1);
     }
     $r = mysqli_fetch_array($q);
-    $id = $r['id'];
+    $id = $r["id"];
 ?>
 <!DOCTYPE html>
 <html>
     <head>
         <meta content="text/html; charset=windows-1252" http-equiv="content-type"/>
         <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
-        <title><?php echo $r["title"] . " - Gasteizko Margolariak"; ?></title>
-        <link rel="shortcut icon" href="<?php echo "$proto$http_host/img/logo/favicon.ico";?>">
+        <title><?=$r["title"]?> - Gasteizko Margolariak</title>
+        <link rel="shortcut icon" href="<?=$server?>/img/logo/favicon.ico">
         <!-- CSS files -->
         <style>
-            <?php 
-                include("../css/ui.css"); 
-                include("../css/blog.css");
-            ?>
+<?php 
+            include("../css/ui.css"); 
+            include("../css/blog.css");
+?>
         </style>
         <!-- CSS for mobile version -->
         <style media="(max-width : 990px)">
-            <?php 
-                include("../css/m/ui.css"); 
-                include("../css/m/blog.css");
-            ?>
+<?php 
+            include("../css/m/ui.css"); 
+            include("../css/m/blog.css");
+?>
         </style>
         <!-- Script files -->
         <script type="text/javascript">
-            <?php
-                include("../script/ui.js");
-                include("../script/blog.js");
-            ?>
+<?php
+            include("../script/ui.js");
+            include("../script/blog.js");
+?>
         </script>
         <!-- Meta tags -->
-        <link rel="canonical" href="<?php echo "$proto$http_host/blog/" . $r['permalink']; ?>"/>
-        <link rel="author" href="<?php echo "$proto$http_host"; ?>"/>
-        <link rel="publisher" href="<?php echo "$proto$http_host"; ?>"/>
-        <meta name="description" content="<?php echo strip_tags($r["text"]);?>"/>
-        <meta property="og:title" content="<?php echo $r["title"] . " - Gasteizko Margolariak"; ?>"/>
-        <meta property="og:url" content="<?php echo "$proto$http_host/blog/" . $r['permalink']; ?>"/>
-        <meta property="og:description" content="<?php echo strip_tags($r["text_$lang"]);?>"/>
-        <?php
-            $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $id ORDER BY idx;");
-            if (mysqli_num_rows($q_image) == 0)
-                $img = "$proto$http_host/img/logo/cover.png";
-            else{
-                $r_image = mysqli_fetch_array($q_image);
-                $img = "$proto$http_host/img/blog/preview/" . $r_image['image'];
-            }
-        ?>
-        <meta property="og:image" content="<?php echo $img;?>"/>
+        <link rel="canonical" href="<?=$server?>/blog/<?=$r["permalink"]?>"/>
+        <link rel="author" href="<?=$server?>"/>
+        <link rel="publisher" href="<?=$server?>"/>
+        <meta name="description" content="<?=strip_tags($r["text"])?>"/>
+        <meta property="og:title" content="<?=$r["title"]?> - Gasteizko Margolariak"/>
+        <meta property="og:url" content="<?=$server?>/blog/<?=$r["permalink"]?>"/>
+        <meta property="og:description" content="<?=strip_tags($r["text_$lang"])?>"/>
+<?php
+        $q_image = mysqli_query($con, "SELECT image FROM post_image WHERE post = $id ORDER BY idx;");
+        if (mysqli_num_rows($q_image) == 0)
+            $img = "$server/img/logo/cover.png";
+        else{
+            $r_image = mysqli_fetch_array($q_image);
+            $img = "$server/img/blog/preview/" . $r_image["image"];
+        }
+?>
+        <meta property="og:image" content="<?=$img?>"/>
         <meta property="og:site_name" content="Gasteizko Margolariak"/>
         <meta property="og:type" content="article"/>
-        <meta property="og:locale" content="<?php echo $lang;?>"/>
+        <meta property="og:locale" content="<?=$lang?>"/>
         <meta property="article:section" content="Blog"/>
-        <!--     TODO: Review time format     -->
-        <meta property="article:published-time" content="<?php echo $r['time'];?>"/>
-        <meta property="article:modified-time" content="<?php echo $r['time'];?>"/>
+        <meta property="article:published-time" content="<?=$r["time"]?>"/>
+        <meta property="article:modified-time" content="<?=$r["time"]?>"/>
         <meta property="article:author" content="Gasteizko Margolariak"/>
-        <?php
-            $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post = $id;");
-            $tag_string = "vitoria cuadrilla gasteizko margolariak ";
-            while ($r_tag = mysqli_fetch_array($q_tag))
-                $tag_string = $tag_string . " " . $r_tag['tag']
-        ?>
-        <meta property="article:tag" content="<?php echo $tag_string ?>"/>
+<?php
+        $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post = $id;");
+        $tag_string = "vitoria cuadrilla gasteizko margolariak ";
+        while ($r_tag = mysqli_fetch_array($q_tag))
+            $tag_string = $tag_string . " " . $r_tag["tag"]
+?>
+        <meta property="article:tag" content="<?=$tag_string?>"/>
         <meta name="twitter:card" content="summary"/>
-        <meta name="twitter:title" content="<?php echo $r["title"] . " - Gasteizko Margolariak";?>"/>
-        <meta name="twitter:description" content="<?php echo strip_tags($r["text"]);?>"/>
-        <meta name="twitter:image" content="<?php echo $img;?>"/>
-        <meta name="twitter:url" content="<?php echo "$proto$http_host/blog/$r[permalink]"; ?>"/>
+        <meta name="twitter:title" content="<?=$r["title"]?> - Gasteizko Margolariak"/>
+        <meta name="twitter:description" content="<?=strip_tags($r["text_$lang"])?>"/>
+        <meta name="twitter:image" content="<?=$img?>"/>
+        <meta name="twitter:url" content="<?=$server?>/blog/<?=$r["permalink"]?>"/>
         <meta name="robots" content="index follow"/>
     </head>
     <body>
-        <?php include("../header.php"); ?>
+<?php
+        include("../header.php");
+?>
         <div id="content">
-            <?php include("common/leftpanel.php"); ?>
+<?php
+            include("common/leftpanel.php");
+?>
             <div id="middle_column">
-                <?php
-                    echo "<div itemscope itemtype='http://schema.org/BlogPosting' class='section blog_entry'>\n";
-                    echo "<meta itemprop='inLanguage' content='$lang'/>\n";
-                    echo "<meta itemprop='datePublished dateModified' content='$r[isodate]'/>\n";
-                    echo "<meta itemprop='headline name' content='$r[title]'/>\n";
-                    echo "<meta itemprop='mainEntityOfPage' content='$proto$http_host'/>\n";
-                    echo "<div class='hidden' itemprop='author publisher' itemscope itemtype='http://schema.org/Organization'>\n";
-                    echo "<meta itemprop='legalName' content='Asociaci&oacute;n Cultural Recreativa Gasteizko Margolariak'/>\n";
-                    echo "<meta itemprop='name' content='Gasteizko Margolariak'/>\n";
-                    echo "<meta itemprop='logo' content='$proto$http_host/img/logo/logo.png'/>\n";
-                    echo "<meta itemprop='foundingDate' content='03-02-2013'/>\n";
-                    echo "<meta itemprop='telephone' content='+34637140371'/>\n";
-                    echo "<meta itemprop='url' content='$proto$http_host'/>\n";
-                    echo "</div>\n";
-                    echo("<h3 class='section_title'>$r[title]</h3>\n");
-                    echo("<div class='entry'>\n");
+                <div itemscope itemtype='http://schema.org/BlogPosting' class='section blog_entry'>
+                <meta itemprop='inLanguage' content='<?=$lang?>'/>
+                <meta itemprop='datePublished dateModified' content='<?=$r["isodate"]?>'/>
+                <meta itemprop='headline name' content='<?=$r["title"]?>'/>
+                <meta itemprop='mainEntityOfPage' content='<?=$server?>'/>
+                <div class='hidden' itemprop='author publisher' itemscope itemtype='http://schema.org/Organization'>
+                    <meta itemprop='legalName' content='Asociaci&oacute;n Cultural Recreativa Gasteizko Margolariak'/>
+                    <meta itemprop='name' content='Gasteizko Margolariak'/>
+                    <meta itemprop='logo' content='<?=$server?>/img/logo/logo.png'/>
+                    <meta itemprop='foundingDate' content='03-02-2013'/>
+                    <meta itemprop='telephone' content='+34637140371'/>
+                    <meta itemprop='url' content='<?=$server?>'/>
+                </div>
+                <h3 class='section_title'><?=$r["title"]?></h3>
+                <div class='entry'>
+<?php
                     if ($r_image != null){
-                        echo "<div class='image_container'>\n";
-                        echo "<meta itemprop='image' content='$proto$http_host/img/blog/$r_image[image]'/>\n";
-                        echo "<img class='post_image post_image_large' alt='$r[title]' src='/img/blog/preview/$r_image[image]'/>\n";
-                        echo "</div>\n";
+?>
+                        <div class='image_container'>
+                            <meta itemprop='image' content='<?=$server?>/img/blog/<?=$r_image["image"]?>'/>
+                            <img class='post_image post_image_large' alt='<?=$r["title"]?>' src='/img/blog/preview/<?=$r_image["image"]?>'/>\n";
+                        </div>
+<?php
                     }
-                    echo "<p itemprop='text articleBody'>$r[text]</p>\n";
+?>
+                    <p itemprop='text articleBody'><?=$r["text"]?></p>
+<?php
                     //Other images
                     if ($r_image != null){
-                        echo "<table id='secondary_images'><tr>\n";
-                        while ($r_image = mysqli_fetch_array($q_image)){
-                            echo "<meta itemprop='image' content='$proto$http_host/img/blog/$r_image[image]'/>\n";
-                            echo "<td><img src='/img/blog/preview/$r_image[image]'/></td>\n";
-                        }
-                        echo "</tr></table>\n";
-                    }
-                    # Tags (if any) and date
-                    echo "<hr><table class='post_footer'><tr>\n";
-                    $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post= $id;");
-                    if (mysqli_num_rows($q_tag) > 0){
-                        $tag_string = "<span id='tags' class='desktop'>Tags: ";
-                        $tag_raw = "";
-                        while ($r_tag = mysqli_fetch_array($q_tag)){
-                            $tag_string = $tag_string . "<a href='/blog/buscar/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
-                            $tag_raw = $tag_raw . "$r_tag[tag],";
-                        }
-                        $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
-                        $tag_string = $tag_string . "</span>";
-                        $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
-                        echo "<meta itemprop='keywords' content='$tag_raw'/>\n";
-                        echo "<td><span class='date'>" . formatDate($r['dtime'], $lang) . "</span><br/><br class='mobile'/>$tag_string</td>\n";
-                    }
-                    else{
-                        echo "<td><span class='date'><span class='hidden'>" . formatDate($r['dtime'], $lang) . "</span></td>\n";
+?>
+                        <table id='secondary_images'>
+                            <tr>
+<?php
+                                while ($r_image = mysqli_fetch_array($q_image)){
+?>
+                                    <meta itemprop='image' content='<?=$server?>/img/blog/<?=$r_image["image"]?>'/>
+                                    <td>
+                                        <img src='<?=$server?>/img/blog/preview/<?=$r_image["image"]?>'/>
+                                    </td>
+<?php
+                                }
+?>
+                            </tr>
+                        </table>
+<?php
                     }
-                    #Share
-                    echo "<td class='r_share'><span class='share'><span class='desktop'>$lng[blog_share]</span>\n";
-                    $title = urlencode("$r[title] - $http_host");
-                    $url_f = htmlspecialchars("https://www.facebook.com/sharer/sharer.php?u=$proto$http_host$_SERVER[REQUEST_URI]");
-                    $url_t = htmlspecialchars("https://twitter.com/share?url=$proto$http_host$_SERVER[REQUEST_URI]&text=$title");
-                    $url_g = htmlspecialchars("https://plus.google.com/share?url=$proto$http_host$_SERVER[REQUEST_URI]");
-                    echo "<a href='$url_f' target='_blank'><img class='share_icon' alt='Facebook' src='$proto$http_host/img/social/facebook.gif'/></a>\n";
-                    echo "<a href='$url_t' target='_blank'><img class='share_icon' alt='Twitter' src='$proto$http_host/img/social/twitter.gif'/></a>\n";
-                    echo "<a href='$url_g' target='_blank'><img class='share_icon' src='$proto$http_host/img/social/googleplus.gif' alt='Google+'/></a>\n";
-                    echo "</span></td>\n";
-                    echo "</tr></table>\n";
+?>
+                    <hr>
+                    <table class='post_footer'>
+                        <tr>
+<?php
+                            # Tags (if any) and date
+                            $q_tag = mysqli_query($con, "SELECT tag FROM post_tag WHERE post= $id;");
+                            if (mysqli_num_rows($q_tag) > 0){
+                                $tag_string = "<span id='tags' class='desktop'>Tags: ";
+                                $tag_raw = "";
+                                while ($r_tag = mysqli_fetch_array($q_tag)){
+                                    $tag_string = $tag_string . "<a href='$server/blog/buscar/tag/$r_tag[tag]'>$r_tag[tag]</a>, ";
+                                    $tag_raw = $tag_raw . "$r_tag[tag],";
+                                }
+                                $tag_string = substr($tag_string, 0, strlen($tag_string) - 2);
+                                $tag_string = $tag_string . "</span>";
+                                $tag_raw = substr($tag_raw, 0, strlen($tag_raw) - 1);
+?>
+                                <meta itemprop='keywords' content='<?=$tag_raw?>'/>
+                                <td>
+                                    <span class='date'><?=formatDate($r["dtime"], $lang)?></span>
+                                    <br/><br class='mobile'/>
+                                    <?=$tag_string?>
+                                </td>
+<?php
+                            }
+                            else{
+?>
+                                <td>
+                                    <span class='date'>
+                                        <span class='hidden'><?=formatDate($r["dtime"], $lang)?>
+                                    </span>
+                                </td>
+<?php
+                            }
+                            #Share
+?>
+                            <td class='r_share'>
+                                <span class='share'>
+                                    <span class='desktop'>$lng[blog_share]</span>
+<?php
+                                    $title = urlencode("$r[title] - $http_host");
+                                    $url_f = htmlspecialchars("https://www.facebook.com/sharer/sharer.php?u=$server$_SERVER[REQUEST_URI]");
+                                    $url_t = htmlspecialchars("https://twitter.com/share?url=$server$_SERVER[REQUEST_URI]&text=$title");
+                                    $url_g = htmlspecialchars("https://plus.google.com/share?url=$server$_SERVER[REQUEST_URI]");
+?>
+                                    <a href='$url_f' target='_blank'><img class='share_icon' alt='Facebook' src='$server/img/social/facebook.gif'/></a>\n";
+                                    <a href='$url_t' target='_blank'><img class='share_icon' alt='Twitter' src='$server/img/social/twitter.gif'/></a>\n";
+                                    <a href='$url_g' target='_blank'><img class='share_icon' src='$server/img/social/googleplus.gif' alt='Google+'/></a>\n";
+                                </span>
+                            </td>
+                        </tr>
+                    </table> <!-- .post_footer -->
+<?php
                     #Comments
-                    if ($r['comments'] == 1){
-                        echo "<hr>\n";
+                    if ($r["comments"] == 1){
                         $q_comment = mysqli_query($con, "SELECT id, post, DATE_FORMAT(dtime, '%Y-%m-%dT%T') AS isodate, dtime, user, username, lang, text FROM post_comment WHERE post = $id AND approved = 1 ORDER BY dtime;");
                         $count = mysqli_num_rows($q_comment);
-                        echo "<meta itemprop='commentCount interactionCount' content='$count'/>\n";
+?>
+                        <hr/>
+                        <meta itemprop='commentCount interactionCount' content='<?=$count?>'/>
+<?php
                         switch ($count){
                             case 0:
-                                echo "<h4><meta itemprop='interactionCount' content='0'/></meta>$lng[blog_comments_0]</h4>\n";
+                                $comment_count = "<h4><meta itemprop='interactionCount' content='0'/></meta>$lng[blog_comments_0]</h4>";
                                 break;
                             case 1:
-                                echo "<h4><span itemprop='interactionCount'>1</span> $lng[blog_comments_1]</h4>\n";
+                               $comment_count = "<h4><span itemprop='interactionCount'>1</span> $lng[blog_comments_1]</h4>";
                                 break;
                             default:
-                                echo "<h4><span itemprop='interactionCount'>$count</span> $lng[blog_comments_multiple]</h4>\n";
-                        }
-                        echo "<div id='comment_list'>\n";
-                        //WARNING: If changes are done here, do the same in comment.php
-                        while ($r_comment = mysqli_fetch_array($q_comment)){
-                            echo "<div itemprop='comment' itemscope itemtype='http://schema.org/UserComments' id='comment_$r_comment[id]' class='comment'>\n";
-                            //When official users are implementes, see if there is user or username
-                            echo "<span itemprop='creator' class='comment_user'>$r_comment[username]</span>\n";
-                            echo "<span class='comment_date date'><meta itemprop='commentTime' content='$r_comment[isodate]'/>" . formatDate($r_comment['dtime'], $lang) . "</span>\n";
-                            echo "<p itemprop='commentText' class='comment_text'>$r_comment[text]</p>";
-                            echo "<hr class='comment_line'/>\n";
-                            echo "</div>\n";
+                                $comment_count = "<h4><span itemprop='interactionCount'>$count</span> $lng[blog_comments_multiple]</h4>";
                         }
-                        echo "</div>\n";
-                        #Comment form
-                        echo "<div class='comment' id='comment_new'>\n";
-                        echo "<form id='comment_form' method='post' action='/' onsubmit='event.preventDefault();postComment($id, \"$lang\");'>\n";
-                        echo "<textarea id='new_comment_text' name='text' maxlength='1800' onChange='defaultInputBorder(this);' onKeyDown='defaultInputBorder(this);' placeholder='$lng[blog_placeholder_text]'></textarea>\n";
-                        echo "<input type='hidden' name='id' value='$id'>\n";
-                        echo "<div id='identification_form'>\n";
-                        echo "<br><input id='new_comment_user' name='user' maxlength='50' type='text' placeholder='$lng[blog_placeholder_name]' onChange='defaultInputBorder(this);' onKeyDown='defaultInputBorder(this);'/>\n";
-                        echo "<input type='submit' value='$lng[blog_send]'/>\n";
-                        echo "</div>\n";
-                        echo "</form>\n";
-                        echo "</div>\n";
+?>
+                        <?=$comment_count?>
+                        <div id='comment_list'>
+<?php
+                            //WARNING: If changes are done here, do the same in comment.php
+                            while ($r_comment = mysqli_fetch_array($q_comment)){
+?>
+                                <div itemprop='comment' itemscope itemtype='http://schema.org/UserComments' id='comment_<?=$r_comment["id"]?>' class='comment'>
+                                    <span itemprop='creator' class='comment_user'><?=$r_comment["username"]?></span>
+                                    <span class='comment_date date'>
+                                        <meta itemprop='commentTime' content='<?=$r_comment["isodate"]?>'/>
+                                        <?=formatDate($r_comment["dtime"], $lang)?>
+                                    </span>
+                                    <p itemprop='commentText' class='comment_text'><?=$r_comment["text"]?></p>
+                                    <hr class='comment_line'/>
+                                </div>
+<?php
+                            }
+?>
+                        </div> <!-- #comment_list -->
+                        <div class='comment' id='comment_new'>
+                            <form id='comment_form' method='post' action='/' onsubmit='event.preventDefault();postComment(<?=$id?>, "<?=$lang?>");'>
+                                <textarea id='new_comment_text' name='text' maxlength='1800' onChange='defaultInputBorder(this);' onKeyDown='defaultInputBorder(this);' placeholder='<?=$lng["blog_placeholder_text"]?>'></textarea>
+                                <input type='hidden' name='id' value='<?=$id?>'>
+                                <div id='identification_form'>
+                                    <br>
+                                    <input id='new_comment_user' name='user' maxlength='50' type='text' placeholder='<?=$lng["blog_placeholder_name"]?>' onChange='defaultInputBorder(this);' onKeyDown='defaultInputBorder(this);'/>
+                                    <input type='submit' value='<?=$lng["blog_send"]?>'/>
+                                </div>
+                            </form>
+                        </div> <!-- .comment_new -->
+<?php
                     }
                     else{
-                        echo "<h4>$lng[blog_comments_closed]</h4>";
+?>
+                        <h4><?=$lng["blog_comments_closed"]?></h4>
+<?php
                     }
-                    echo "</div></div>\n";
-                ?>
-            </div>
-            <?php include("common/rightpanel.php"); ?>
-        </div>
-        <?php
+?>
+                </div> <!-- .entry -->
+            </div> <!-- #middle_column -->
+<?php
+            include("common/rightpanel.php");
+?>
+        </div> <!-- .content -->
+<?php
             include("../footer.php");
             $ad = ad($con, $lang, $lng); 
             stats($ad, $ad_static, "blog", "$id");
-        ?>
+?>
     </body>
 </html>

+ 8 - 19
www/functions.php

@@ -303,25 +303,14 @@
         }
         return $cut;
     }
-    
-    /****************************************************
-    * Increases version value in table settings by one. *
-    * Helpfull for the app to know when to perform a    * 
-    * full sync. Must be called after every INSERT,     *
-    * UPDATE or DELETE query to the database.           *
-     ****************************************************/
-    function version(){
-        $con = startdb('rw');
-        mysqli_query($con, 'UPDATE settings SET value = value + 1 WHERE name = "version";');
-    }
-    
-    /****************************************************
-        * Shows an ad at random. It does that one in three  *
-        * times, and only one per session (inserts a cookie *
-        * to know if the ad has been shown. A sponsor has   *
-        * more chances of having his ad popping the more it *
-    * contributes with Gasteizko Margolariak.           *
-        ****************************************************/
+
+    /*****************************************************
+     * Shows an ad at random. It does that one in three  *
+     * times, and only one per session (inserts a cookie *
+     * to know if the ad has been shown. A sponsor has   *
+     * more chances of having his ad popping the more it *
+     * contributes with Gasteizko Margolariak.           *
+     *****************************************************/
     function ad($con, $lang, $lng){
         $id = -1;
         //If the user hasn't still see an add on this session