<?php
2 /*-------------------------------------------------------+
3 | PHP-Fusion Content Management System
4 | Copyright (C) PHP-Fusion Inc
5 | https://www.php-f...
6 +--------------------------------------------------------+
7 | Filename: articles.php
8 | Author: Nick Jones (Digitanium)
9 +--------------------------------------------------------+
10 | This program is released as free software under the
11 | Affero GPL license. You can redistribute it and/or
12 | modify it under the terms of this license which you
13 | can read by viewing the included agpl.txt or online
14 | at www.gnu.org/licen... Removal of this
15 | copyright header is strictly prohibited without
16 | written permission from the original author(s).
17 +--------------------------------------------------------*/
18 require_once "maincore.php";
19 require_once THEMES."templates/header.php";
20 include LOCALE.LOCALESET."articles.php";
21
22 # Breadcrumbs
23 # Original Code from Rizald "Elyn" Maxwell
24 # Rewritten for 7.02 by MarcusG
25
26 $isTrue = false;
27 $str = "";
28 if (isset($_GET['article_id'])&& isnum($_GET['article_id'])){
29 $result = dbquery(
30 "SELECT ta.article_cat, tac.article_cat_name, ta.article_id, ta.article_subject FROM ".DB_ARTICLES." ta
31 LEFT JOIN ".DB_ARTICLE_CATS." tac ON ta.article_cat=tac.article_cat_id
32 WHERE article_id='".$_GET['article_id']."'"
33 );
34 if (dbrows($result)) {
35 $data = dbarray($result);
36 $str .= "<a href='".FUSION_SELF."'><strong>".$locale['404']."</strong></a>";
37 $str .= " » <a href='".FUSION_SELF."?cat_id=".$data['article_cat']."'>".$data['article_cat_name']."</a>";
38 $str .= " » <a href='".FUSION_SELF."?article_id=".$_GET['article_id']."'>".$data['article_subject']."</a>";
39 $isTrue = true;
40 }
41 } elseif (isset($_GET['cat_id']) && isnum($_GET['cat_id'])){
42 $result = dbquery(
43 "SELECT article_cat_name FROM ".DB_ARTICLE_CATS."
44 WHERE article_cat_id='".$_GET['cat_id']."'");
45 if (dbrows($result)) {
46 $data = dbarray($result);
47 $str .= "<a href='".FUSION_SELF."'><strong>".$locale['404']."</strong></a>";
48 $str .= " » <a href='".FUSION_SELF."?cat_id=".$_GET['cat_id']."'>".$data['article_cat_name']."</a>";
49 $isTrue = true;
50 }
51 }
52
53 if($isTrue){
54 opentable($locale['405']);
55 echo $str;
56 closetable();
57 }
58
59 # end of breadcrumbs
60
61 add_to_title($locale['global_200'].$locale['400']);
62
63 if (isset($_GET['article_id']) && isnum($_GET['article_id'])) {
64 $result = dbquery(
65 "SELECT ta.article_subject, ta.article_article, ta.article_breaks,
66 ta.article_datestamp, ta.article_reads, ta.article_allow_comments, ta.article_allow_ratings,
67 tac.article_cat_id, tac.article_cat_name,
68 tu.user_id, tu.user_name, tu.user_status
69 FROM ".DB_ARTICLES." ta
70 INNER JOIN ".DB_ARTICLE_CATS." tac ON ta.article_cat=tac.article_cat_id
71 LEFT JOIN ".DB_USERS." tu ON ta.article_name=tu.user_id
72 WHERE ".groupaccess('article_cat_access')." AND article_id='".$_GET['article_id']."' AND article_draft='0'"
73 );
74 if (dbrows($result)) {
75 require_once INCLUDES."comments_include.php";
76 require_once INCLUDES."ratings_include.php";
77 $data = dbarray($result);
78 if (!isset($_GET['rowstart']) || !isnum($_GET['rowstart'])) { $_GET['rowstart'] = 0; }
79 if ($_GET['rowstart'] == 0) { $result = dbquery("UPDATE ".DB_ARTICLES." SET article_reads=article_reads+1 WHERE
article_id='".$_GET['article_id']."'"); }
80 $article = preg_split("/<!?--s*pagebreaks*-->/i", stripslashes($data['article_article']));
81 $pagecount = count($article);
82 $article_subject = stripslashes($data['article_subject']);
83 $article_info = array(
84 "article_id" => $_GET['article_id'],
85 "cat_id" => $data['article_cat_id'],
86 "cat_name" => $data['article_cat_name'],
87 "user_id" => $data['user_id'],
88 "user_name" => $data['user_name'],
89 "user_status" => $data['user_status'],
90 "article_date" => $data['article_datestamp'],
91 "article_breaks" => $data['article_breaks'],
92 "article_comments" => dbcount("(comment_id)", DB_COMMENTS, "comment_type='A' AND comment_item_id='".$_GET['article_id']."'"),
93 "article_reads" => $data['article_reads'],
94 "article_allow_comments" => $data['article_allow_comments']
95 );
96 add_to_title($locale['global_201'].$article_subject, $article[$_GET['rowstart']]);
97 echo "<!--pre_article-->";
98 render_article($article_subject, $article[$_GET['rowstart']], $article_info);
99 echo "<!--sub_article-->";
100 if ($pagecount > 1) {
101 echo "<div align='center' style='margin-top:5px;'>n".makepagenav($_GET['rowstart'], 1, $pagecount, 3,
FUSION_SELF."?article_id=".$_GET['article_id']."&")."n</div>n";
102 }
103 if ($data['article_allow_comments']) { showcomments("A", DB_ARTICLES, "article_id", $_GET['article_id'],
FUSION_SELF."?article_id=".$_GET['article_id']); }
104 if ($data['article_allow_ratings']) { showratings("A", $_GET['article_id'], FUSION_SELF."?article_id=".$_GET['article_id']); }
105 } else {
106 redirect(FUSION_SELF);
107 }
108 } elseif (!isset($_GET['cat_id']) || !isnum($_GET['cat_id'])) {
109 opentable($locale['400']);
110 echo "<!--pre_article_idx-->n";
111
112 //$result = dbquery("SELECT article_cat_id, article_cat_name, article_cat_description FROM ".DB_ARTICLE_CATS." WHERE
".groupaccess('article_cat_access')." ORDER BY article_cat_name");
113
114 // NEW QUERY
115 $result = dbquery(
116 "SELECT ac.article_cat_id, ac.article_cat_name, ac.article_cat_description, COUNT(a.article_cat) AS article_count FROM ".DB_ARTICLES." a
117 LEFT JOIN ".DB_ARTICLE_CATS." ac ON a.article_cat=ac.article_cat_id
118 WHERE ".groupaccess('ac.article_cat_access')."
119 GROUP BY ac.article_cat_id
120 ORDER BY ac.article_cat_name"
121 );
122
123 $rows = dbrows($result);
124 if ($rows) {
125 $counter = 0; $columns = 2;
126 echo "<table cellpadding='0' cellspacing='0' width='100%'>n<tr>n";
127 while ($data = dbarray($result)) {
128 if ($counter != 0 && ($counter % $columns == 0)) { echo "</tr>n<tr>n"; }
129 //$num = dbcount("(article_cat)", DB_ARTICLES, "article_cat='".$data['article_cat_id']."' AND article_draft='0'");
130 echo "<td valign='top' width='50%' class='tbl article_idx_cat_name'><!--article_idx_cat_name--><a
href='".FUSION_SELF."?cat_id=".$data['article_cat_id']."'>".$data['article_cat_name']."</a> <span
class='small2'>(".$data['article_count'].")</span>";
131 if ($data['article_cat_description'] != "") { echo "<br />n<span class='small'>".$data['article_cat_description']."</span>"; }
132 echo "</td>n";
133 $counter++;
134 }
135 echo "</tr>n</table>n";
136 } else {
137 echo "<div style='text-align:center'><br />n".$locale['401']."<br /><br />n</div>n";
138 }
139 echo "<!--sub_article_idx-->n";
140 closetable();
141 } else {
142 $res = 0;
143 $result = dbquery("SELECT article_cat_name, article_cat_sorting, article_cat_access FROM ".DB_ARTICLE_CATS." WHERE
article_cat_id='".$_GET['cat_id']."'");
144 if (dbrows($result) != 0) {
145 $cdata = dbarray($result);
146 if (checkgroup($cdata['article_cat_access'])) {
147 $res = 1;
148 add_to_title($locale['global_201'].$cdata['article_cat_name']);
149 opentable($locale['400'].": ".$cdata['article_cat_name']);
150 echo "<!--pre_article_cat-->";
151 $rows = dbcount("(article_id)", DB_ARTICLES, "article_cat='".$_GET['cat_id']."' AND article_draft='0'");
152 if (!isset($_GET['rowstart']) || !isnum($_GET['rowstart'])) { $_GET['rowstart'] = 0; }
153 if ($rows != 0) {
154 $result = dbquery(
155 "SELECT article_id, article_subject, article_snippet, article_datestamp FROM ".DB_ARTICLES."
156 WHERE article_cat='".$_GET['cat_id']."' AND article_draft='0' ORDER BY ".$cdata['article_cat_sorting']." LIMIT
".$_GET['rowstart'].",".$settings['articles_per_page']
157 );
158 $numrows = dbrows($result); $i = 1;
159 while ($data = dbarray($result)) {
160 $class = ($i%2 ? "tbl1" : "tbl2");
161 if ($data['article_datestamp'] + 604800 > time() + ($settings['timeoffset'] * 3600)) {
162 $new = " <span class='small' style='color:green;'>[".$locale['402']."]</span>";
163 } else {
164 $new = "";
165 }
166 echo "<div class='".$class."'><strong><a
href='".FUSION_SELF."?article_id=".$data['article_id']."'>".$data['article_subject']."</a></strong>".$new."<br
/>n".preg_replace("/<!?--s*pagebreaks*-->/i", "", stripslashes($data['article_snippet']))."</div>";
167 echo ($i != $numrows ? "<hr />n" : "n"); $i++;
168 }
169 echo "<!--sub_article_cat-->";
170 closetable();
171 if ($rows > $settings['articles_per_page']) echo "<div align='center' style=';margin-top:5px;'>n".makepagenav($_GET['rowstart'],
$settings['articles_per_page'], $rows, 3, FUSION_SELF."?cat_id=".$_GET['cat_id']."&")."n</div>n";
172 } else {
173 echo "<div style='text-align:center'>".$locale['403']."</div>n";
174 echo "<!--sub_article_cat-->";
175 closetable();
176 }
177 }
178 }
179 if ($res == 0) { redirect(FUSION_SELF); }
180 }
181
182 require_once THEMES."templates/footer.php";
183 ?>