root/tags/1.1.0/archive.php

Revision 1707, 5.3 KB (checked in by jeena, 10 months ago)

changed require prepend.inc.php instead setting.inc.php

Line 
1<?php
2 require_once('.'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.'prepend.inc.php');
3
4 $get = strip($_GET);
5 if(isset($get['cat'])) $cat_y_link = "cat=".$get['cat'];
6 $yl = new Year_Links($get['y'], JLOG_START_YEAR, archive(), $l, $cat_y_link);
7 if(isset($get['show'])) $p = (int) escape_for_mysql($get['show']);
8 else $p = 0;
9 $amount = 5;
10
11 $c['meta']['robots']       = "noindex, follow";
12   
13    if(isset($get['cat'])) {
14
15
16      $c['meta']['title'] = $categories->get($categories->get_id($get['cat']), 'name');
17      $c['main'] .= "<h2>".$l['content_categories_header']." ".$categories->get($categories->get_id($get['cat']), 'name')." ".$yl->get_selected_year()."</h2>";
18      $c['main'] .= "<p>".$categories->get($categories->get_id($get['cat']), 'description')."</p>";
19
20        $sql_archive = "
21         SELECT
22          ".JLOG_DB_CONTENT.".*,
23          ".JLOG_DB_CONTENT.".date as mysql_date,
24          DATE_FORMAT(".JLOG_DB_CONTENT.".date, '%c') AS month,
25          DATE_FORMAT(".JLOG_DB_CONTENT.".date, '%Y') AS year,
26          UNIX_TIMESTAMP(".JLOG_DB_CONTENT.".date) AS date
27          FROM ".JLOG_DB_CONTENT."
28          LEFT JOIN ".JLOG_DB_CATASSIGN."
29           ON ".JLOG_DB_CONTENT.".id = ".JLOG_DB_CATASSIGN.".content_id
30            WHERE ".JLOG_DB_CATASSIGN.".cat_id = '".escape_for_mysql($categories->get_id($get['cat']))."'
31            AND YEAR(".JLOG_DB_CONTENT.".date) = '".escape_for_mysql($yl->get_selected_year())."'
32          ORDER BY mysql_date DESC;";
33
34        $c['main'] .= "<p>".$yl->get_linklist()."</p>";
35
36    }
37    elseif(empty($get['y'])) {
38        $c['meta']['title'] = $l['content_archive_header'];
39        $c['main'] = "<h2>".$c['meta']['title']."</h2>";
40       
41        $sql_archive = "SELECT
42                    *,
43                    date as mysql_date,
44                    DATE_FORMAT(date, '%c') AS month,
45                    DATE_FORMAT(".JLOG_DB_CONTENT.".date, '%Y') AS year,
46                    UNIX_TIMESTAMP(date) AS date
47              FROM ".JLOG_DB_CONTENT."
48              WHERE section = 'weblog'
49              ORDER BY mysql_date DESC
50              LIMIT ".$p.", ".$amount.";";
51
52        $sql_count = "SELECT count(*) AS count FROM ".JLOG_DB_CONTENT." WHERE section = 'weblog'";
53
54        $count_query = new Query($sql_count);
55            if($count_query->error()) {
56                echo "<pre>\n";
57                echo $count_query->getError();
58                echo "</pre>\n";
59                die();
60            }
61        $_count = $count_query->fetch();
62        $count_query->free();
63        $count = $_count['count'];
64    }
65    else {
66        if(!empty($get['m'])) $where_month = " AND MONTH(date) = '".escape_for_mysql($get['m'])."'";
67        $c['meta']['title'] = $l['content_archive_header'];
68        $c['main'] = "<h2>".$c['meta']['title']." ".$yl->get_selected_year()."</h2>";
69
70        $sql_archive = "SELECT
71                    *,
72                    date as mysql_date,
73                    DATE_FORMAT(date, '%c') AS month,
74                    DATE_FORMAT(".JLOG_DB_CONTENT.".date, '%Y') AS year,
75                    UNIX_TIMESTAMP(date) AS date
76              FROM ".JLOG_DB_CONTENT.$where_from."
77              WHERE
78               YEAR(date) = '".escape_for_mysql($yl->get_selected_year())."'
79              ".$where_month."
80               AND section = 'weblog'
81              ORDER BY mysql_date;";
82
83        $c['main'] .= "<p>".$yl->get_linklist()."</p>";
84    }
85 
86 $cc = count_comments();
87
88    $archive = new Query($sql_archive);
89     if($archive->error()) {
90        echo "<pre>\n";
91        echo $archive->getError();
92        echo "</pre>\n";
93        die();
94     }
95
96$months = array_flip($l['months']);
97
98if($archive->numRows() > 0) {
99    // initialise variables to keep track of last posts month and year
100    $last_month = false;
101    $last_year = false;
102   
103    while ($daten = $archive->fetch()) {
104     if(empty($daten)) break 1;
105     
106     // did we already reach a new month or year?
107     if (($last_month != $daten['month']) OR ($last_year != $daten['year'])) {
108            if ($last_month) { $c['main'] .=  "    </div>\n"; }
109            $c['main'] .= "   <h3>".array_search($daten['month'], $months)." ".$daten['year']."</h3>\n";
110            $c['main'] .= "    <div class='archive'>\n";
111            // set last month and year to values of current post
112            $last_month = $daten['month'];
113            $last_year = $daten['year'];
114     }
115      $c['main'] .= do_teaser($daten, $cc, "<h4>", "</h4>");
116    }
117    if(empty($get['y'])) {
118        $c['main'] .= "<p class='archivenavigation'>";
119        if(($p - $amount) >= 0) {
120            $c['main'] .= "<a href='?show=".($p - $amount)."'><strong>&lt;&mdash;</strong> ".$l['content_archive_preview']."</a>";
121            $c['meta']['aditionalheader'] .= '  <link rel="prev" href="?show='.($p - $amount).'" title="'.$l['content_archive_preview'].'" />'."\n";
122        }
123        if((($p - $amount) >= 0) && (($p + $amount) < $count)) $c['main'] .= " | ";
124        if(($p + $amount) < $count) {
125            $c['main'] .= "<a href='?show=".($p + $amount)."'>".$l['content_archive_next']." <strong>&mdash;&gt;</strong></a>";
126            $c['meta']['aditionalheader'] .= '  <link rel="next" href="?show='.($p + $amount).'" title="'.$l['content_archive_next'].'" />'."\n";
127        }
128        $c['main'] .= "</p>";
129     }
130     $c['main'] .= "</div>\n";
131}
132
133
134require(JLOG_BASEPATH.'scripts'.DIRECTORY_SEPARATOR.'do_template.php');
135echo $body;
136?>
Note: See TracBrowser for help on using the browser.