| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
|
| 5 |
function weblink_user($type, &$edit, &$user) {
|
| 6 |
switch ($type) {
|
| 7 |
case "register_form":
|
| 8 |
return form_hidden("weblink_new", 1);
|
| 9 |
case "edit_form":
|
| 10 |
return form_select(t("Open new window for weblinks"), "weblink_new", $user->weblink_new, array(t("Disabled"), t("Enabled")), t("Create a new window when you click on a weblink"));
|
| 11 |
}
|
| 12 |
}
|
| 13 |
|
| 14 |
function weblink_perm() {
|
| 15 |
return array("create weblinks", "access weblink monitor");
|
| 16 |
}
|
| 17 |
|
| 18 |
function weblink_help($type= "admin/help#weblink") {
|
| 19 |
switch ($type) {
|
| 20 |
case "admin/help#weblink":
|
| 21 |
$output = "<p>" . t("The weblinks module is used to create <i>links</i> to other websites or pages") . "</p>";
|
| 22 |
$output .= "<p>". t("The weblink monitor tracks or crawls other interesting web sites and displays their latest modification dates. Vistors to the host site learn about relevant sites and can easily see if there is new content. Here is how it works:") ."</p>";
|
| 23 |
$output .= "<ul>";
|
| 24 |
$output .= " <li>" . t("The site administrator selects certain weblinks for monitoring from the administration page.") . "</li>";
|
| 25 |
$output .= " <li>" . t("Drupal's cron function, triggers the weblink module to check all the monitored web sites for recent changes or updates. (A page is updated when there is a <i>x</i>-byte difference since the last time it checked, where <i>x</i> is a configuration option.)") . "</li>";
|
| 26 |
$output .= " <li>" . t("The module exports both a page and a block that display the registered sites ordered by their last modification date.") . "</li>";
|
| 27 |
$output .= "</ul>";
|
| 28 |
break;
|
| 29 |
|
| 30 |
case "admin/system/modules#description":
|
| 31 |
$output = t("a weblinks module, with integrated monitoring");
|
| 32 |
break;
|
| 33 |
}
|
| 34 |
|
| 35 |
return $output;
|
| 36 |
}
|
| 37 |
|
| 38 |
function weblink_settings() {
|
| 39 |
$output = form_select(t("Link display mode"), "weblink_link_display", variable_get("weblink_link_display", 0), array("as title", "as url"), t("This setting toggles how the link is displayed in the node links bar. If 'as title' is selected the node's title shall be used. If 'as url' is selected the link's url shall be used."));
|
| 40 |
|
| 41 |
foreach (taxonomy_get_vocabularies("weblink") as $vid => $voc) {
|
| 42 |
$vocs[$vid] = $voc->name;
|
| 43 |
}
|
| 44 |
if ($vocs) {
|
| 45 |
$output .= form_select(t("Navigation vocabulary"), "weblink_nav_vocabulary", variable_get("weblink_nav_vocabulary", ""), $vocs, t("One of the taxonomy vocabularies will be the navigation tree."));
|
| 46 |
}
|
| 47 |
else {
|
| 48 |
$output .= form_item(t("Navigation vocabulary"), t("You must assign one or more %l to the weblink module", array ("%l" => l(t("vocabularies"), "admin/taxonomy"))));
|
| 49 |
}
|
| 50 |
$output .= form_select(t("Links per block"), "weblink_block_count", variable_get("weblink_link_count", 10), array(5=>"5",10=>"10",15=>"15",20=>"20"), t("show x links per block"));
|
| 51 |
$output .= form_textfield(t("Links per page"), "weblink_pager_term", variable_get("weblink_pager_term", 0), 3, 5, t('Show x links per page. "0" disables paging / shows all links.'));
|
| 52 |
return $output;
|
| 53 |
}
|
| 54 |
|
| 55 |
function weblink_conf_filters() {
|
| 56 |
$output = form_select(t("Weblink filter"), "weblink_filter_enabled", variable_get("weblink_filter_enabled", 0), array(t("Disabled"), t("Enabled")), t("When enabled, weblink codes will be replaced by a link to visit the real website. Syntax: [weblink:node_id] or [weblink:http://url.from.weblinks.com/]"));
|
| 57 |
return $output;
|
| 58 |
}
|
| 59 |
|
| 60 |
function weblink_target($node) {
|
| 61 |
global $user;
|
| 62 |
return ($user->weblink_new ? array("title" => $node->title, "target" => "blank") : array("title" => $node->title));
|
| 63 |
}
|
| 64 |
|
| 65 |
function weblink_filter($text) {
|
| 66 |
|
| 67 |
$match = array();
|
| 68 |
if (preg_match_all("/\[weblink:(\d+)\]/i", $text, $match)) {
|
| 69 |
for ($i = 0; $i <= count($match[1]); $i++) {
|
| 70 |
$node = node_load(array("nid" => $match[1][$i]));
|
| 71 |
$text = str_replace($match[0][$i], l($node->title, "weblink/goto/$node->nid", weblink_target($node)), $text);
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
$match = array();
|
| 76 |
if (preg_match_all("/\[weblink:(\S+?)\]/i", $text, $match)) {
|
| 77 |
for ($i = 0; $i <= count($match[1]); $i++) {
|
| 78 |
$result = db_query("SELECT nid FROM {weblink} WHERE weblink = '%s'", $match[1][$i]);
|
| 79 |
$weblink = db_fetch_object($result);
|
| 80 |
$node = node_load(array("nid" => $weblink->nid));
|
| 81 |
$text = str_replace($match[0][$i], l($node->title, "weblink/goto/$node->nid", weblink_target($node)), $text);
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
return $text;
|
| 86 |
}
|
| 87 |
|
| 88 |
function weblink_node($field) {
|
| 89 |
$info["name"] = t("weblink");
|
| 90 |
$info["description"] = t("The weblink module is used to create <i>links</i> to other websites or pages.");
|
| 91 |
|
| 92 |
return $info[$field];
|
| 93 |
}
|
| 94 |
|
| 95 |
function weblink_access($op, $node) {
|
| 96 |
if ($op == "view") {
|
| 97 |
return $node->status;
|
| 98 |
}
|
| 99 |
|
| 100 |
if ($op == "create") {
|
| 101 |
return user_access("create weblinks");
|
| 102 |
}
|
| 103 |
}
|
| 104 |
|
| 105 |
function weblink_save($op, $node) {
|
| 106 |
|
| 107 |
if ($op == "approve") {
|
| 108 |
return array("status" => 1, "promote" => 1);
|
| 109 |
}
|
| 110 |
|
| 111 |
if ($op == "create") {
|
| 112 |
if (user_access("administer nodes")) {
|
| 113 |
return array("weblink");
|
| 114 |
}
|
| 115 |
else {
|
| 116 |
return array("status" => 0, "body" => filter($node->body), "moderate" => 1, "teaser" => filter($node->teaser), "weblink" => $node->weblink);
|
| 117 |
}
|
| 118 |
}
|
| 119 |
|
| 120 |
if ($op == "decline") {
|
| 121 |
return array("status" => 0, "promote" => 0);
|
| 122 |
}
|
| 123 |
|
| 124 |
if ($op == "update") {
|
| 125 |
return array("weblink");
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
function weblink_link($type, $node = 0) {
|
| 130 |
global $user;
|
| 131 |
if (($type == "page") && user_access("access content")) {
|
| 132 |
$links[] = l(t("links"), "weblink", array("title" => t("view the weblinks directory")));
|
| 133 |
}
|
| 134 |
|
| 135 |
if ($type == "system") {
|
| 136 |
if (user_access("create weblinks")) {
|
| 137 |
menu("node/add/weblink", t("weblink"), "page");
|
| 138 |
}
|
| 139 |
}
|
| 140 |
|
| 141 |
if ($type == "node" && $node->type == "weblink") {
|
| 142 |
foreach (taxonomy_node_get_terms($node->nid) as $term) {
|
| 143 |
$links[] = l(t("return to %term", array("%term" => $term->name)), "weblink/view/$term->tid");
|
| 144 |
}
|
| 145 |
// construct link title
|
| 146 |
if (variable_get("weblink_link_display", "0")) {
|
| 147 |
$link_display = $node->weblink;
|
| 148 |
$title_display = $node->title;
|
| 149 |
}
|
| 150 |
else {
|
| 151 |
$link_display = $node->title;
|
| 152 |
$title_display = $node->weblink;
|
| 153 |
}
|
| 154 |
|
| 155 |
// produce link
|
| 156 |
$links[] = l(t("visit %link", array("%link" => $link_display)), "weblink/goto/$node->nid", weblink_target($node)) ." (". $node->click .")";
|
| 157 |
}
|
| 158 |
|
| 159 |
return $links ? $links : array();
|
| 160 |
}
|
| 161 |
|
| 162 |
function weblink_form(&$node, &$help, &$error) {
|
| 163 |
|
| 164 |
if ($error) {
|
| 165 |
$weblink_desc .= theme("error", $error["weblink"]);
|
| 166 |
} else {
|
| 167 |
$weblink_desc = t("Links should be submitted in a form similar to http://www.example.com/");
|
| 168 |
}
|
| 169 |
|
| 170 |
$output .= form_textfield(t("Link"), "weblink", $node->weblink, 60, 128, $weblink_desc);
|
| 171 |
|
| 172 |
if (user_access("administer nodes")) {
|
| 173 |
$period = array(900 => format_interval(900), 1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 64800 => format_interval(64800), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200));
|
| 174 |
$threshold = array(1 => "1 byte", 10 => "10 bytes", 20 => "20 bytes", 40 => "40 bytes", 60 => "60 bytes", 80 => "80 bytes", 100 => "100 bytes", 120 => "120 bytes", 140 => "140 bytes", 160 => "160 bytes", 320 => "320 bytes", 640 => "640 bytes");
|
| 175 |
|
| 176 |
$output .= "<table width=\"100%\" cellpadding=\"0\"><tr valign=\"top\">";
|
| 177 |
$output .= "<td>" . form_hidden("monitor", 0);
|
| 178 |
$output .= form_item(t("URL Monitoring"), "<input type=\"checkbox\" class=\"form-checkbox\" name=\"edit[monitor]\" value=\"1\"" . ($node->monitor ? " checked=\"checked\"" : "") . " />" . t("Monitor URL"), t("Do you want this URL monitored for changes?")) . "</td>";
|
| 179 |
|
| 180 |
$output .= "<td>" . form_select(t("Update interval"), "refresh", ($node->refresh ? $node->refresh : 21600), $period, t("The refresh interval indicating how often you want to check this site for updates. Requires crontab.")) . "</td>";
|
| 181 |
$output .= "<td>" . form_select(t("Change threshold"), "threshold", ($node->threshold ? $node->threshold : 40), $threshold, t("The number of bytes the site must have been modified before considered changed.")) . "</td></tr><tr>";
|
| 182 |
$output .= "<td colspan=\"3\">" . form_textfield(t("URL to monitor"), "feed", $node->feed, 50, 255, t("The URL of the page you want to monitor for updates. Likely to be same as the site's URL but useful to monitor framed pages and more accurate when pointed to a XML/RSS/RDF feed.")) . "</td>";
|
| 183 |
$output .= "</tr></table>";
|
| 184 |
}
|
| 185 |
|
| 186 |
|
| 187 |
if (module_exist("mnogo") && user_access("administer nodes")) {
|
| 188 |
$output .= "<table width=\"100%\" cellpadding=\"0\"><tr valign=\"top\">";
|
| 189 |
$output .= "<td colspan=\"3\">" . form_checkbox(t("Spider this site"), "spider_site", 1, $node->spider_site, t("Use external mnogosearch engine to spider this site")) . "</td></tr><tr>";
|
| 190 |
$output .= "<td colspan=\"3\">" . form_textfield(t("URL to spider"), "spider_url", $node->spider_url, 50, 255, t("The URL of the page you want to spider. All sub pages will be added to the mnogosearch index.")) . "</td>";
|
| 191 |
$output .= "</tr></table>";
|
| 192 |
}
|
| 193 |
|
| 194 |
$taxonomy = taxonomy_node_form("weblink", $node);
|
| 195 |
if (count($taxonomy) > 1) {
|
| 196 |
$output .= "<table width=\"100%\" cellpadding=\"0\"><tr valign=\"top\">";
|
| 197 |
foreach($taxonomy as $tax) {
|
| 198 |
$output .= "<td>$tax</td>";
|
| 199 |
}
|
| 200 |
$output .= "</tr></table>";
|
| 201 |
} else {
|
| 202 |
$output .= implode("<p>", $taxonomy);
|
| 203 |
}
|
| 204 |
|
| 205 |
if ($node->teaser) {
|
| 206 |
$output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
|
| 207 |
}
|
| 208 |
$output .= form_textarea(t("Body"), "body", $node->body, 60, 20);
|
| 209 |
|
| 210 |
return $output;
|
| 211 |
}
|
| 212 |
|
| 213 |
function weblink_insert($node) {
|
| 214 |
db_query("INSERT INTO {weblink} (nid, weblink, monitor, refresh, threshold, feed, spider_site, spider_url) VALUES ('%d', '%s', '%d', '%d', '%d', '%s', '%d', '%s')", $node->nid, $node->weblink, $node->monitor, $node->refresh, $node->threshold, $node->feed, $node->spider_site, $node->spider_url);
|
| 215 |
}
|
| 216 |
|
| 217 |
function weblink_update($node) {
|
| 218 |
db_query("UPDATE {weblink} SET weblink = '%s', monitor = '%d', refresh = '%d', threshold = '%d', feed = '%s', spider_site = '%d', spider_url = '%s' WHERE nid = '%d'", $node->weblink, $node->monitor, $node->refresh, $node->threshold, $node->feed, $node->spider_site, $node->spider_url, $node->nid);
|
| 219 |
}
|
| 220 |
|
| 221 |
function weblink_delete(&$node) {
|
| 222 |
db_query("DELETE FROM {weblink} WHERE nid = '%s'", $node->nid);
|
| 223 |
}
|
| 224 |
|
| 225 |
function weblink_validate(&$node) {
|
| 226 |
$result = db_query("SELECT * from {weblink} WHERE weblink = '%s' and nid <> '%d'", $node->weblink, $node->nid);
|
| 227 |
if (db_num_rows($result) > 0) {
|
| 228 |
$weblink = db_fetch_object($result);
|
| 229 |
$othernode = node_load(array("nid" => $weblink->nid));
|
| 230 |
return array("weblink" => t("A weblink ") . l($othernode->title, "admin/node/edit/$othernode->nid", array("title" => $othernode->title)) . t(" with that link already exists"));
|
| 231 |
}
|
| 232 |
}
|
| 233 |
|
| 234 |
function weblink_cron() {
|
| 235 |
$result = db_query("SELECT * FROM {weblink} WHERE monitor = 1 AND (checked = 0 OR checked + refresh < %d) ORDER by change_stamp ASC", time());
|
| 236 |
|
| 237 |
while ($site = db_fetch_object($result)) {
|
| 238 |
weblink_monitor($site);
|
| 239 |
}
|
| 240 |
}
|
| 241 |
|
| 242 |
function weblink_load($node) {
|
| 243 |
$weblink = db_fetch_object(db_query("SELECT * FROM {weblink} WHERE nid = '%d'", $node->nid));
|
| 244 |
|
| 245 |
return $weblink;
|
| 246 |
}
|
| 247 |
|
| 248 |
function weblink_block($op = "list", $delta = 0) {
|
| 249 |
if ($op == "list") {
|
| 250 |
$blocks[0]["info"] = t("Top 10 weblinks");
|
| 251 |
$blocks[1]["info"] = t("Latest 10 weblinks");
|
| 252 |
$blocks[2]["info"] = t("Monitored weblinks");
|
| 253 |
return $blocks;
|
| 254 |
}
|
| 255 |
else {
|
| 256 |
switch ($delta) {
|
| 257 |
case 0:
|
| 258 |
$block["subject"] = t("Top weblinks");
|
| 259 |
$block["content"] = weblink_block_top(variable_get("weblink_block_count",10));
|
| 260 |
return $block;
|
| 261 |
case 1:
|
| 262 |
$block["subject"] = t("Latest weblinks");
|
| 263 |
$block["content"] = weblink_block_new(variable_get("weblink_block_count",10));
|
| 264 |
return $block;
|
| 265 |
case 2:
|
| 266 |
$block["subject"] = t("Monitored weblinks");
|
| 267 |
$block["content"] = weblink_monitor_list(variable_get("weblink_block_count",10)) ."<div style=\"text-align: right;\">". l(t("more"), "weblink/monitor", array("title" => t("Monitor external weblinks."))) ."</div>";
|
| 268 |
return $block;
|
| 269 |
}
|
| 270 |
}
|
| 271 |
}
|
| 272 |
|
| 273 |
function weblink_block_top($limit = 10) {
|
| 274 |
global $user;
|
| 275 |
|
| 276 |
$result = db_query_range("SELECT n.nid, n.title, n.status, n.moderate, w.weblink, w.click FROM {node} n LEFT JOIN {weblink} w on n.nid = w.nid WHERE n.type='weblink' AND n.status = 1 AND n.moderate = 0 ORDER by w.click DESC", 0, $limit);
|
| 277 |
|
| 278 |
while ($node = db_fetch_object($result)) {
|
| 279 |
$links[] = $node;
|
| 280 |
}
|
| 281 |
|
| 282 |
return theme("weblink_monitor_list",$links);
|
| 283 |
}
|
| 284 |
|
| 285 |
function weblink_block_new($limit = 10) {
|
| 286 |
global $user;
|
| 287 |
|
| 288 |
$result = db_query_range("SELECT n.nid, n.title, n.status, n.moderate, w.weblink, w.click FROM {node} n LEFT JOIN {weblink} w on n.nid = w.nid WHERE n.type='weblink' AND n.status = 1 AND n.moderate = 0 ORDER by n.created DESC", 0, $limit);
|
| 289 |
|
| 290 |
while ($node = db_fetch_object($result)) {
|
| 291 |
$links[] = $node;
|
| 292 |
}
|
| 293 |
|
| 294 |
return theme("weblink_monitor_list",$links);
|
| 295 |
}
|
| 296 |
|
| 297 |
function weblink_monitor_list($limit = 10) {
|
| 298 |
global $user;
|
| 299 |
|
| 300 |
$result = db_query_range("SELECT * FROM {weblink} WHERE change_stamp > ". (time() - 604800) ." ORDER BY change_stamp DESC", 0, $limit);
|
| 301 |
|
| 302 |
$hour = -1;
|
| 303 |
$list = -1;
|
| 304 |
$inlist = false;
|
| 305 |
$output .= "<div class=\"item-list\">";
|
| 306 |
while ($weblink = db_fetch_object($result)) {
|
| 307 |
$node = node_load(array("nid" => $weblink->nid));
|
| 308 |
watchdog("warning", "Weblink: " . $node->title);
|
| 309 |
if ($hour != floor((time() - $node->change_stamp) / 3600)) {
|
| 310 |
$hour = floor((time() - $node->change_stamp) / 3600);
|
| 311 |
if ($hour < 12) {
|
| 312 |
if ($inlist) {
|
| 313 |
$output .= "</ul>";
|
| 314 |
$inlist = false;
|
| 315 |
}
|
| 316 |
if ($hour == 0) {
|
| 317 |
$output .= t("Updated less than one hour ago:");
|
| 318 |
}
|
| 319 |
else {
|
| 320 |
$output .= format_plural($hour, "Updated an hour ago:", "Updated %count hours ago:");
|
| 321 |
}
|
| 322 |
}
|
| 323 |
else if ($list) {
|
| 324 |
if ($inlist) {
|
| 325 |
$output .= "</ul>";
|
| 326 |
$inlist = false;
|
| 327 |
}
|
| 328 |
$output .= format_plural($hour, "Updated more than an hour ago:", "Updated more than %count hours ago:");
|
| 329 |
$list = 0;
|
| 330 |
}
|
| 331 |
}
|
| 332 |
if (!$inlist) {
|
| 333 |
$output .= "<ul>";
|
| 334 |
$inlist = true;
|
| 335 |
}
|
| 336 |
$output .= "<li>" .
|
| 337 |
l($node->title, "weblink/goto/$node->nid", $user->weblink_new ? array("title" => $node->title, "target" => "blank") : array("title" => $node->title)) . "</li>";
|
| 338 |
}
|
| 339 |
if ($inlist) $output .= "</ul>";
|
| 340 |
$output .= "</div>";
|
| 341 |
return $output;
|
| 342 |
}
|
| 343 |
|
| 344 |
function weblink_page() {
|
| 345 |
$id = arg(2);
|
| 346 |
$tid = arg(2);
|
| 347 |
$vid = arg(3);
|
| 348 |
|
| 349 |
$output ="";
|
| 350 |
switch (arg(1)) {
|
| 351 |
case "view":
|
| 352 |
$output .= theme("weblink_page_view", $tid, $vid, taxonomy_get_parents($tid), _weblink_get_structure($tid), taxonomy_get_related($tid), _weblink_get_links($tid));
|
| 353 |
break;
|
| 354 |
case "goto":
|
| 355 |
$output .= weblink_page_goto($id);
|
| 356 |
break;
|
| 357 |
case "goto2":
|
| 358 |
$output .= weblink_page_goto2($id);
|
| 359 |
break;
|
| 360 |
case "monitor":
|
| 361 |
$output .= theme("weblink_page_monitored", weblink_monitor_list(100));
|
| 362 |
default:
|
| 363 |
$output .= theme("weblink_page_default", _weblink_get_structure());
|
| 364 |
break;
|
| 365 |
}
|
| 366 |
return $output;
|
| 367 |
}
|
| 368 |
|
| 369 |
function _weblink_get_structure($tid = 0) {
|
| 370 |
// this structure is a good candidate for caching
|
| 371 |
$categories = taxonomy_get_children($tid, variable_get("weblink_nav_vocabulary", ""));
|
| 372 |
$tree = taxonomy_get_tree(variable_get("weblink_nav_vocabulary", ""));
|
| 373 |
|
| 374 |
foreach (array_keys($categories) as $term_id) {
|
| 375 |
$terms = array();
|
| 376 |
$children = taxonomy_get_tree(variable_get("weblink_nav_vocabulary", ""), $term_id, 1);
|
| 377 |
$terms[] = $term_id;
|
| 378 |
foreach ($children as $term) {
|
| 379 |
$terms[] = $term->tid;
|
| 380 |
$categories[$term_id]->subterms[$term->tid] = $term->name;
|
| 381 |
}
|
| 382 |
$result = db_query("SELECT COUNT(*) AS c FROM {term_node} t, {node} n WHERE t.nid = n.nid AND tid IN (". implode(",", $terms) .") AND n.type = 'weblink' AND n.status = 1 AND n.moderate = 0");
|
| 383 |
while ($term = db_fetch_object($result)) {
|
| 384 |
$categories[$term_id]->link_count = $term->c;
|
| 385 |
}
|
| 386 |
}
|
| 387 |
|
| 388 |
return $categories ? $categories : array();
|
| 389 |
}
|
| 390 |
|
| 391 |
function _weblink_get_links($tid) {
|
| 392 |
$result = ($weblink_pager_term = variable_get("weblink_pager_term", 0))
|
| 393 |
? pager_query("SELECT n.nid, n.title, n.teaser, n.status, n.moderate, w.weblink, w.click FROM {node} n, {term_node} t, {weblink} w WHERE t.nid = n.nid AND n.nid = w.nid AND tid = $tid AND n.type='weblink' AND n.status = 1 AND n.moderate = 0", $weblink_pager_term)
|
| 394 |
: db_query("SELECT n.nid, n.title, n.teaser, n.status, n.moderate, w.weblink, w.click FROM {node} n, {term_node} t, {weblink} w WHERE t.nid = n.nid AND n.nid = w.nid AND tid = %d AND n.type='weblink' AND n.status = 1 AND n.moderate = 0", $tid)
|
| 395 |
;
|
| 396 |
|
| 397 |
while ($node = db_fetch_object($result)) {
|
| 398 |
$links[] = $node;
|
| 399 |
}
|
| 400 |
|
| 401 |
return $links ? $links : array();
|
| 402 |
}
|
| 403 |
|
| 404 |
function weblink_page_goto($id) {
|
| 405 |
db_query("UPDATE {weblink} SET click = click + 1 where nid = '%d'", $id);
|
| 406 |
$result = db_query("SELECT weblink FROM {weblink} WHERE nid = '%d'", $id);
|
| 407 |
$wl = db_fetch_object($result);
|
| 408 |
header("Location: $wl->weblink");
|
| 409 |
}
|
| 410 |
|
| 411 |
function weblink_page_goto2($id) {
|
| 412 |
db_query("UPDATE {weblink} SET click = click + 1 where nid = '%d'", $id);
|
| 413 |
$result = db_query("SELECT feed FROM {weblink} WHERE nid = '%d'", $id);
|
| 414 |
$wl = db_fetch_object($result);
|
| 415 |
header("Location: $wl->feed");
|
| 416 |
}
|
| 417 |
|
| 418 |
function weblink_monitor($site) {
|
| 419 |
|
| 420 |
// Load the associated node record
|
| 421 |
$node = node_load(array("nid" => $site->nid));
|
| 422 |
|
| 423 |
/*
|
| 424 |
** Check whether the site is properly configured:
|
| 425 |
*/
|
| 426 |
|
| 427 |
$url = "";
|
| 428 |
if (!ereg("^http://|https://|ftp://", $node->weblink)) {
|
| 429 |
watchdog("warning", t("weblink: invalid or missing URL for") . " '". $node->title ."'", l(t("edit site"), "admin/node/edit/". $node->nid));
|
| 430 |
} else {
|
| 431 |
$url = $node->weblink;
|
| 432 |
}
|
| 433 |
|
| 434 |
if (!ereg("^http://|https://|ftp://", $node->feed) && !$url) {
|
| 435 |
watchdog("warning", t("weblink: invalid or missing URL to monitor for") . " '". $node->title ."'", l(t("edit site"), "admin/node/edit/". $node->nid));
|
| 436 |
} else {
|
| 437 |
// Overwrite previously set link
|
| 438 |
$url = $node->weblink;
|
| 439 |
}
|
| 440 |
|
| 441 |
/*
|
| 442 |
** Grab the page and update the database if required:
|
| 443 |
*/
|
| 444 |
|
| 445 |
$success = true;
|
| 446 |
|
| 447 |
// Use curl if we can - take from neighbour module
|
| 448 |
if (function_exists("curl_version")) {
|
| 449 |
$ch = curl_init();
|
| 450 |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
| 451 |
curl_setopt($ch, CURLOPT_URL, $url);
|
| 452 |
curl_setopt($ch, CURLOPT_HEADER, 1);
|
| 453 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
| 454 |
$data = curl_exec($ch);
|
| 455 |
if (!$data) {
|
| 456 |
$success = false;
|
| 457 |
}
|
| 458 |
} else {
|
| 459 |
if ($fp = @fopen($node->weblink, "r")) {
|
| 460 |
while (!feof($fp)) {
|
| 461 |
$data .= fgets($fp, 128);
|
| 462 |
}
|
| 463 |
fclose($fp);
|
| 464 |
} else {
|
| 465 |
$success = false;
|
| 466 |
}
|
| 467 |
}
|
| 468 |
|
| 469 |
if ($success) {
|
| 470 |
if (abs($node->size - strlen($data)) >= $node->threshold) {
|
| 471 |
db_query("UPDATE {weblink} SET size = %d, change_stamp = %d, checked = %d WHERE nid = '%d'", strlen($data), time(), time(), $node->nid);
|
| 472 |
// module_invoke_all("website_change", $data);
|
| 473 |
}
|
| 474 |
else {
|
| 475 |
db_query("UPDATE {weblink} SET checked = %d WHERE nid = '%d'", time(), $node->nid);
|
| 476 |
}
|
| 477 |
}
|
| 478 |
else {
|
| 479 |
watchdog("warning", t("weblink: failed to syndicate from") ." '". $node->title ."'". ($errstr ? ": $errstr" : ""));
|
| 480 |
}
|
| 481 |
}
|
| 482 |
|
| 483 |
/**
|
| 484 |
* Displays an explanation of the weblink module on the compose_tips module page
|
| 485 |
*/
|
| 486 |
function weblink_compose_tips() {
|
| 487 |
if (variable_get("weblink_filter_enabled", 0)) {
|
| 488 |
return array(t("You may create links to items stored with the weblink module using a special syntax. The weblink code(s) will be replaced by a link to visit the real website. Syntax: <i>[weblink:node_id] or [weblink:http://url.from.weblinks.com/]</i>"));
|
| 489 |
}
|
| 490 |
}
|
| 491 |
|
| 492 |
/**
|
| 493 |
@addtogroup theme_system
|
| 494 |
|
| 495 |
Weblink module specific theme functions
|
| 496 |
@{
|
| 497 |
**/
|
| 498 |
|
| 499 |
/**
|
| 500 |
Prints the weblink index page
|
| 501 |
|
| 502 |
@param categories
|
| 503 |
**/
|
| 504 |
function theme_weblink_page_default($categories) {
|
| 505 |
|
| 506 |
$output = "<table width=\"100%\" cellspacing=\"10\">";
|
| 507 |
foreach ($categories as $term_id => $category) {
|
| 508 |
if ($count % 3 == 0) {
|
| 509 |
$output .= "<tr>";
|
| 510 |
}
|
| 511 |
|
| 512 |
$output .= "<td width=\"33%\" valign=\"top\">";
|
| 513 |
$output .= l($category->name, "weblink/view/$term_id");
|
| 514 |
$output .= " (". $category->link_count .")";
|
| 515 |
if ($category->subterms) {
|
| 516 |
foreach ($category->subterms as $subtid => $subterm) {
|
| 517 |
$t[] = l($subterm, "weblink/view/$subtid");
|
| 518 |
unset($subterm);
|
| 519 |
}
|
| 520 |
$output .= "<br />". implode(", ", $t) ;
|
| 521 |
unset($t);
|
| 522 |
}
|
| 523 |
$output .= "</td>";
|
| 524 |
|
| 525 |
if ($count % 3 == 2) {
|
| 526 |
$output .= "</tr>";
|
| 527 |
}
|
| 528 |
|
| 529 |
$count++;
|
| 530 |
}
|
| 531 |
$output .= "</table>";
|
| 532 |
$output .= "<br />";
|
| 533 |
$output .= l(t("create weblink"), "node/add/weblink", array("title" => t("add a new weblink")));
|
| 534 |
|
| 535 |
print theme("header");
|
| 536 |
print theme("box", t("Weblink directory"), $output);
|
| 537 |
print theme("footer");
|
| 538 |
|
| 539 |
}
|
| 540 |
|
| 541 |
/**
|
| 542 |
Prints the weblink monitored links page
|
| 543 |
|
| 544 |
@param content
|
| 545 |
**/
|
| 546 |
function theme_weblink_page_monitored($content) {
|
| 547 |
print theme("header");
|
| 548 |
print theme("box", t("Monitored Weblinks"), $content);
|
| 549 |
print theme("footer");
|
| 550 |
}
|
| 551 |
|
| 552 |
/**
|
| 553 |
Prints a weblink category page
|
| 554 |
|
| 555 |
@param tid
|
| 556 |
@param vid
|
| 557 |
@param parents
|
| 558 |
@param children
|
| 559 |
@param related
|
| 560 |
@param links
|
| 561 |
**/
|
| 562 |
function theme_weblink_page_view($tid, $vid, $parents, $children, $related, $links) {
|
| 563 |
|
| 564 |
$page_term = taxonomy_get_term($tid);
|
| 565 |
|
| 566 |
$vocab = taxonomy_get_vocabulary($page_term->vid);
|
| 567 |
|
| 568 |
$title = t("Browsing %term", array("%term" => $page_term->name));
|
| 569 |
$output = t("Return to %vocabulary", array("%vocabulary" => l($vocab->name, "weblink", array("title" => t("Return to the links directory")))));
|
| 570 |
$output .= "<br />";
|
| 571 |
|
| 572 |
// Now see if we have any parents
|
| 573 |
foreach ($parents as $parent) {
|
| 574 |
$output .= t("Go to parent category %name", array("%name" => l(check_output($parent->name), "weblink/view/$parent->tid/$parent->vid", array("title" => t("Go to parent category %description", array("%description" => $parent->description))))));
|
| 575 |
$output .= "<br />";
|
| 576 |
}
|
| 577 |
|
| 578 |
// Now see if we have any children
|
| 579 |
if ($children) {
|
| 580 |
$output .= t("Subcategories:") ."<br />";
|
| 581 |
foreach ($children as $child) {
|
| 582 |
$output .= " "; // hey, even Google users blanks to format!
|
| 583 |
$output .= l(check_output($child->name), "weblink/view/$child->tid/$parent->vid", array("title" => t("Go to category %description", array("%description" => $child->description))));
|
| 584 |
$output .= " (". $child->link_count .")<br />";
|
| 585 |
}
|
| 586 |
}
|
| 587 |
|
| 588 |
// Now see if we have any relations
|
| 589 |
foreach ($related as $related) {
|
| 590 |
$output .= t("Go to related category %name", array("%name" => l(check_output($related->name), "weblink/view/$related->tid/$related->vid", array("title" => t("Go to related category %description", array("%description" => $related->description))))));
|
| 591 |
$output .= "<br />";
|
| 592 |
}
|
| 593 |
|
| 594 |
$output .= "<hr /><ul>";
|
| 595 |
|
| 596 |
foreach ($links as $node) {
|
| 597 |
$output .= theme("weblink_node_short" , $node);
|
| 598 |
}
|
| 599 |
|
| 600 |
$output .= "</ul>";
|
| 601 |
|
| 602 |
$output .= "<br /><br />";
|
| 603 |
$output .= l(t("create weblink"), "node/add/weblink", array("title" => t("add a new weblink")));
|
| 604 |
|
| 605 |
print theme("header");
|
| 606 |
print theme("box", $title, $output);
|
| 607 |
if ($weblink_pager_term = variable_get("weblink_pager_term", 0)) {
|
| 608 |
print pager_display(NULL, $weblink_pager_term);
|
| 609 |
}
|
| 610 |
print theme("footer");
|
| 611 |
}
|
| 612 |
|
| 613 |
/**
|
| 614 |
Returns a short weblink item display
|
| 615 |
|
| 616 |
@param node
|
| 617 |
**/
|
| 618 |
function theme_weblink_node_short($node) {
|
| 619 |
global $user;
|
| 620 |
$output = "<li>";
|
| 621 |
$output .= l($node->title, "weblink/goto/$node->nid", weblink_target($node));
|
| 622 |
$output .= " - ". $node->weblink ."<br />";
|
| 623 |
$output .= $node->teaser;
|
| 624 |
$output .= " (". format_plural($node->click, "1 hit", "%count hits") . " - ";
|
| 625 |
$output .= l(t("detail"), "node/view/$node->nid", array("title" => t("Read details, read and add comments.")));
|
| 626 |
if (user_access("administer nodes")) {
|
| 627 |
$output .= " - " . l(t("administer"), "admin/node/edit/$node->nid", array("title" => t("Administer this node.")));
|
| 628 |
}
|
| 629 |
$output .= ")";
|
| 630 |
$output .= "</li>";
|
| 631 |
|
| 632 |
return $output;
|
| 633 |
}
|
| 634 |
|
| 635 |
/**
|
| 636 |
Returns a list of weblinks
|
| 637 |
|
| 638 |
@param links
|
| 639 |
**/
|
| 640 |
function theme_weblink_monitor_list($links) {
|
| 641 |
if (is_array($links) && (sizeof($links) > 0)) {
|
| 642 |
foreach ($links as $node) {
|
| 643 |
$items[] = l($node->title, "weblink/goto/$node->nid", weblink_target($node));
|
| 644 |
}
|
| 645 |
return theme("item_list",$items);
|
| 646 |
}
|
| 647 |
}
|
| 648 |
|
| 649 |
/** @} End of addtogroup theme_system **/
|
| 650 |
|
| 651 |
?>
|