summaryrefslogtreecommitdiff
path: root/modules/headline.module
blob: e4393195bc36edb6a957af97fbac2d838875dcad (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php

$module = array("page"  => "headline_page",
                "cron"  => "headline_cron",
                "help"  => "headline_help",
                "block" => "headline_block",
                "admin" => "headline_admin",
                "export" => "headline_export");

include_once "includes/common.inc";
include_once "modules/backend.class";

function headline_blocks() {
  global $theme;

  // Get channel info:
  $result = db_query("SELECT * FROM channel ORDER BY id");

  $theme->header();

  print "<TABLE BORDER=\"0\">\n";
  while ($channel = db_fetch_object($result)) {
    if ($state % 3 == 0) print " <TR>\n";

    print "  <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">\n";

    // Load backend from database:
    $backend = new backend($channel->id);

    if ($backend->headlines) {
      unset($content);
      foreach ($backend->headlines as $headline) $content .= "<LI>$headline</LI>\n";
    }
    else {
      $content = "no headlines available\n";
    }

    // Print backend box to screen:
    $theme->box($backend->site, $content);
    print " </TD>\n";

    if ($state % 3 == 2) print " </TR>\n";

    $state += 1;
  }
  print "</TABLE>\n";

  $theme->footer();
}

function headline_page() {
  global $type;

  switch($type) {
    case "rdf":
      headline_rdf();
      break;
    default:
      headline_blocks();
  }
}

function headline_cron() {
  $result = db_query("SELECT * FROM channel");
  while ($channel = db_fetch_object($result)) {
    $backend = new Backend($channel->id);
  }
}

function headline_help() {
 ?>
  <P>Drupal's headline module both imports and exports RDF/RSS headlines.</P>
  <P>A lot of news-oriented websites are now publishing news (headlines) and making their content available through XML, RSS and RDF backend files.  They syndicate free content and allow retrieval and further transmission, aggregation, and online publication. In its current state, drupal's headline module supports RDF and RSS backends.</P>
  <P>RSS was originally developed by Netscape to allow adding news channels to "My Netscape" sites, but it has since become adopted as the <I>de facto</I> net standard for distributing headlines and brief dynamic texts.</P>
  <P>The headline module goes out to a list of configured news sites once an hour or so (driven by cron), downloads new RSS/RDF data and makes it available to your visitors.  In addition, your headlines are exported as well and can be retrieved by other sites from <CODE>http://yourdomain.com/export/headlines.rdf</CODE>.</P>
 <?php
}

function headline_block() {
  $result = db_query("SELECT * FROM channel");
  while ($channel = db_fetch_object($result)) {
    $backend = new Backend($channel->id);

    if ($backend->headlines) {
      unset($content);
      foreach ($backend->headlines as $headline) {
        $content .= "<LI>$headline</LI>\n";
      }
    }
    else {
      $content = "no headlines available";
    }

    $blocks[$channel->id]["subject"] = $backend->site;
    $blocks[$channel->id]["content"] = $content;
    $blocks[$channel->id]["info"] = "$backend->site headlines";
    $blocks[$channel->id]["link"] = $backend->url;
  }
  return $blocks;
}

function headline_admin_display() {
  global $theme;

  // Get channel info:
  $result = db_query("SELECT * FROM channel ORDER BY id");

  $output .= "<TABLE BORDER=\"1\" CELLSPADDING=\"2\" CELLSPACING=\"2\">\n";
  $output .= " <TH>site</TH><TH>contact</TH><TH>last update</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";

  while ($channel = db_fetch_object($result)) {
    // Load backend from database:
    $backend = new backend($channel->id);

    $output .= "<TR>\n";
    $output .= " <TD>". format_url($backend->url, $backend->site) ."</TD>\n";
    $output .= " <TD>". format_email($backend->contact) ."</TD>\n";
    $output .= " <TD ALIGN=\"center\">". ($backend->timestamp == 1 ? "failed" : format_interval(time() - $backend->timestamp) ." ago") ."</TD>\n";
    $output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=headline&op=refresh&id=$backend->id\">refresh</A></TD>\n";
    $output .= " <TD ALIGN=\"center\"><A HREF=\"admin.php?mod=headline&op=delete&id=$backend->id\">delete</A></TD>\n";
    $output .= "</TR>\n";
  }

  $output .= "</TABLE>\n";

  print $output;
}

function headline_admin_add() {
  $output .= " <FORM ACTION=\"admin.php?mod=headline\" METHOD=\"post\">\n";
  $output .= "  <P>\n";
  $output .= "   <B>Site name:</B><BR>\n";
  $output .= "   <INPUT TYPE=\"text\" NAME=\"site\" SIZE=\"50\">\n";
  $output .= "  </P>\n";
  $output .= "  <P>\n";
  $output .= "   <B>URL:</B><BR>\n";
  $output .= "   <INPUT TYPE=\"text\" NAME=\"url\" SIZE=\"50\">\n";
  $output .= "  </P>\n";
  $output .= "  <P>\n";
  $output .= "   <B>Backend file:</B><BR>\n";
  $output .= "   <INPUT TYPE=\"text\" NAME=\"backend\" SIZE=\"50\">\n";
  $output .= "  </P>\n";
  $output .= "  <P>\n";
  $output .= "   <B>Contact information:</B><BR>\n";
  $output .= "   <INPUT TYPE=\"text\" NAME=\"contact\" SIZE=\"50\">\n";
  $output .= "  </P>\n";
  $output .= "  <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Add backend\">\n";
  $output .= " </FORM>\n";

  print $output;
}

function headline_admin_rehash() {
  global $repository;
  module_rehash_blocks("headline", $repository["headline"]);
}

function headline_admin() {
  global $op, $id, $site, $url, $backend, $contact;

  print "<SMALL><A HREF=\"admin.php?mod=headline&op=add\">add new channel</A> | <A HREF=\"admin.php?mod=headline\">overview</A> | <A HREF=\"admin.php?mod=headline&op=help\">help</A></SMALL><HR>";

  switch($op) {
    case "add":
      headline_admin_add();
      break;
    case "delete":
      $backend = new backend($id);
      $backend->delete();
      headline_admin_rehash();
      headline_admin_display();
      break;
    case "help":
      headline_help();
      break;
    case "refresh":
      $backend = new backend($id);
      $backend->refresh();
      headline_admin_display();
      break;
    case "Add backend":
      $backend = new backend($id, $site, $url, $backend, $contact);
      $backend->add();
      headline_admin_rehash();
      // fall through:
    default:
      headline_admin_display();
  }
}

function headline_export($uri) {
  global $site_name, $site_url, $status, $HTTP_REFERER, $HTTP_USER_AGENT;

  if ($uri[1] == "headlines.rdf") {
    watchdog("message", "grabbed 'headlines.rdf' - referring url: $HTTP_REFERER - user agent: $HTTP_USER_AGENT");

    header("Content-Type: text/plain");

    print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
    print "<rdf:RDF\n";
    print " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
    print " xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">\n";

    print "<channel>\n";
    print " <title>$site_name</title>\n";
    print " <link>$site_url</link>\n";
    print " <description>$site_name</description>\n";
    print "</channel>\n";

    $result = db_query("SELECT * FROM nodes WHERE type = 'story' AND status = '$status[posted]' ORDER BY timestamp DESC LIMIT 10");

    while ($node = db_fetch_object($result)) {
      print "<item>\n";
      print " <title>". check_export($node->title) ."</title>\n";
      print " <link>". $site_url ."node.php?id=$node->nid</link>\n";
      print "</item>\n";
    }

    print "</rdf:RDF>\n";
  }
}

?>