-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutputfunctions.php
More file actions
123 lines (121 loc) · 3.21 KB
/
outputfunctions.php
File metadata and controls
123 lines (121 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php //outputfunctions.php
function trimBody($theText, $lmt=500, $s_chr="\n", $s_cnt=2)
{
$pos = 0;
$trimmed = FALSE;
for ($i = 1; $i <= $s_cnt; $i++)
{
if(@$tmp == strpos($theText, $s_chr, $pos+1))
{
$pos = @$tmp;
$trimmed = TRUE;
}
else
{
$pos = strlen($theText);
$trimmed = FALSE;
break;
}
}
$theText = substr($theText, 0, $pos);
if (strlen($theText) > $lmt) {
$theText = substr($theText, 0, $lmt);
$theText = substr($theText, 0, strrpos($theText, ""));
$trimmed = TRUE;
}
if($trimmed) $theText .= "...";
return $theText;
}
function outputStory($article, $only_snippet = FALSE)
{
global $conn;
if($article)
{
$sql = "SELECT ar.*, usr.name " .
"FROM cms_articles ar " .
"LEFT OUTER JOIN cms_users usr " .
"ON ar.author_id = usr.user_id " .
"WHERE ar.article_id = " . $article;
$result = mysql_query($sql, $conn);
if($row = mysql_fetch_array($result))
{
echo "<h3>" . htmlspecialchars($row["title"]) . "</h3>\n";
echo "<h5><div class=\"byline\">By: " .
htmlspecialchars($row["name"]) .
"</div>";
echo "<div class=\"pubdate\">";
if($row["is_published"] == 1)
{
echo date("F j, Y",strtotime($row["date_published"]));
}
else
{
echo "not yet published";
}
echo "</div></h5>\n";
if($only_snippet)
{
echo "<p>\n";
echo nl2br(htmlspecialchars(trimBody($row["body"])));
echo "</p>\n";
echo "<h4><a href=\"viewarticle.php?article=" .
$row["article_id"] . "\">Full Story...</a></a4><br>\n";
}
else
{
echo "<p>\n";
echo nl2br(htmlspecialchars($row["body"]));
echo "<br/><a href=\"authorinfo.php?author=" . $row["name"] . "\">Author Info</a>";
echo "</p>\n";
}
}
}
}
function showComments($article, $showLink=TRUE)
{
global $conn;
if($article)
{
$sql = "SELECT is_published " .
"FROM cms_articles " .
"WHERE article_id =" . $article;
$result = mysql_query($sql,$conn) or
die("Couldn't look up comments: " . mysql_error());
$row = mysql_fetch_array($result);
$is_published = $row["is_published"];
$sql = "SELECT co.*, usr.name, usr.email " .
"FROM cms_comments co " .
"LEFT OUTER JOIN cms_users usr " .
"ON co.comment_user = usr.user_id " .
"WHERE co.article_id=" . $article .
" ORDER BY co.comment_date DESC";
$result = mysql_query($sql,$conn) or
die("Couldn't look up comments: " . mysql_error());
if($showLink)
{
echo "<h4>" . mysql_num_rows($result) . " Comments";
if(isset($_SESSION["user_id"]) and $is_published) {
echo " / <a href=\"comment.php?article=" . $_GET["article"] .
"\">Add one</a>";
}
echo "</h4>";
}
if(mysql_num_rows($result))
{
echo "<div class=\"scroller\>";
while($row = mysql_fetch_array($result))
{
echo "<span class=\"commentName\">" .
htmlspecialchars($row["name"]) .
"</span><span class=\"commentDate\"> (" .
date("l F j, Y H:i", strtotime($row["comment_date"])) .
")</span>";
echo "<p class=\"commentText\">" .
nl2br(htmlspecialchars($row["comment"])) .
"</p>";
}
echo "</div>";
}
echo "<br/>";
}
}