aboutsummaryrefslogtreecommitdiff
path: root/frontend/notes.php
blob: 1492ed48e9b43c1334dd6e5d9bec28520f6676be (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php

/*
   Cheetah News notes.php
   Copyright (C) 2005, 2006 Wojciech Polak.

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License, or (at your
   option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

require 'lib/functions.php';
require 'lib/mysql.class.php';
require 'lib/local.php';

getvars ('u,t');

if (empty ($u))
  exit;

$db = new Database ();
$userid = '';
$tagUri = 'tag:'.$CONF['site'].',2005:notes';

header ('Content-Type: application/xml; charset=UTF-8');

if ($u == 'guest' && isset ($CONF['guestAccount']))
  $u = $CONF['guestAccount'];

$db->query ("SELECT id FROM user WHERE email='".$db->escape ($u)."'");
if ($db->next_record ())
  $userid = $db->f ('id');

if (isset ($CONF['guestAccount']) && $u == $CONF['guestAccount'])
  $u = 'guest';

$tag = '';
if (!empty ($t))
  $tag = '/'.htmlspecialchars (htmlentities2 ($t));

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n";
echo "<title>".$u.($u[strlen ($u) - 1] != 's' ? "'s" : "'")." Notes and Links</title>\n";
echo "<updated>".gmdate ('Y-m-d\TH:i:s\Z')."</updated>\n";
echo "<author>\n";
echo "<name>".$u."</name>\n";
echo "<email>".$u."</email>\n";
echo "</author>\n";
echo "<rights>Copyright (C) ".gmdate ('Y').' '.$u."</rights>\n";
echo "<generator uri=\"http://".$CONF['site']."/\">Cheetah News Aggregator</generator>\n";
echo "<id>".$tagUri.'/'.$u.(!empty ($t) ? $tag : '')."</id>\n";
echo "<link rel=\"self\" type=\"application/atom+xml\" href=\"http://".
$CONF['site'].'/notes/'.$u.(!empty ($t) ? $tag : '')."\"/>\n";
echo "<icon>http://".$CONF['site']."/images/favicon.png</icon>\n";

if (!empty ($t)) {
  $db->query ("SELECT note.id, note.title, note.date, note.mstamp, note.note FROM note ".
	      "LEFT JOIN jntag ON note.id=jntag.noteid ".
	      "LEFT JOIN ntag ON (ntag.id=jntag.tagid) ".
	      "WHERE note.userid='".$userid."' AND note.public='yes' ".
	      "AND ntag.tag='".$db->escape ($t)."' ".
	      "GROUP BY note.id ORDER BY date DESC LIMIT 0,20");
}
else {
  $db->query ("SELECT id, title, date, mstamp, note FROM note ".
	      "WHERE note.userid='".$userid."' AND public='yes' ".
	      "ORDER BY date DESC LIMIT 0,20");
}
while ($db->next_record ())
{
  $pubDate = gmdate ('Y-m-d\TH:i:s\Z', strtotime ($db->f ('mstamp')));

  echo "<entry>\n";
  echo "<id>".$tagUri.'/'.$u.(!empty ($t) ? $tag : '').'/'.$db->f ('id')."</id>\n";
  echo "<updated>".$pubDate."</updated>\n";
  echo "<title>".htmlspecialchars (htmlentities2 ($db->f ('title')))."</title>\n";
  echo "<content type=\"xhtml\" xml:space=\"preserve\">\n";
  echo "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
  echo nl2br2 (createLinks (htmlspecialchars (htmlentities2 ($db->f ('note')))))."\n";
  echo "</div>\n";
  echo "</content>\n";
  echo "</entry>\n";
}

echo "</feed>\n";

function htmlentities2 ($htmlcode) {
  static $htmlEntities;
  static $entitiesDecoded;
  static $utf8Entities;
  if (!isset ($htmlEntities))
    $htmlEntities = array_values (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES));
  if (!isset ($entitiesDecoded))
    $entitiesDecoded = array_keys (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES));
  if (!isset ($utf8Entities)) {
    $num = count ($entitiesDecoded);
    for ($u = 0; $u < $num; $u++)
      $utf8Entities[$u] = '&#'.ord ($entitiesDecoded[$u]).';';
  }
  return str_replace ($htmlEntities, $utf8Entities, $htmlcode);
}

function nl2br2 ($str) {
  return preg_replace ('/(\r\n|\n|\r)/', '', nl2br ($str));
}

function createLinks ($str)
{
  $lines = split ("\n", $str);
  for ($z = 0; $z < count ($lines); $z++) {
    $tmp = split (' ', $lines[$z]);
    for ($i = 0; $i < count ($tmp); $i++) {
      if (strstr ($tmp[$i], 'www.') && !strstr ($tmp[$i], 'http://'))
	$tmp[$i] = '<a href="http://'.$tmp[$i].'">'.$tmp[$i].'</a>';
      else if (strstr ($tmp[$i], 'http://') ||
	       strstr ($tmp[$i], 'https://') ||
	       strstr ($tmp[$i], 'ftp://'))
	$tmp[$i] = '<a href="'.$tmp[$i].'">'.$tmp[$i].'</a>';
      else if (strstr ($tmp[$i], '@') &&
	       $tmp[$i][0] != '@' &&
	       $tmp[$i][strlen ($tmp[$i]) - 1] != '@')
	$tmp[$i] = '<a href="mailto:'.$tmp[$i].'">'.$tmp[$i].'</a>';
    }
    $lines[$z] = join (' ', $tmp);
  }
  return join ("\n", $lines);
}

?>

Return to:

Send suggestions and report system problems to the System administrator.