function simplenews_statistics_open_page in Simplenews Statistics 7
Same name and namespace in other branches
- 7.2 includes/simplenews_statistics.pages.inc \simplenews_statistics_open_page()
Check and log newsletter opens.
1 call to simplenews_statistics_open_page()
- simplenews_statistics_click_page in includes/
simplenews_statistics.pages.inc - Check and log newsletter URL clicks.
1 string reference to 'simplenews_statistics_open_page'
- simplenews_statistics_menu in ./
simplenews_statistics.module - Implements hook_menu().
File
- includes/
simplenews_statistics.pages.inc, line 11 - Contains page function for simplenews statistics.
Code
function simplenews_statistics_open_page($nid, $snid, $terminate = TRUE) {
// Call possible decoders for nid & snid in modules implementing the hook.
// Modules implementing this hook should validate this input themself because
// we can not know what kind of string they will generate.
$hook = 'simplenews_statistics_decode';
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
if (function_exists($function)) {
$nid = $function($nid, 'nid');
$snid = $function($snid, 'snid');
}
}
// Once decoded properly we can know for sure that nid & snid are numeric.
if (!is_numeric($nid) || !is_numeric($snid)) {
watchdog('simplenews_statistics', 'Simplenews statistics open called with illegal parameter(s). Node ID: @nid. Subscriber ID: @snid', array(
'@nid' => $nid,
'@snid' => $snid,
));
}
else {
$subscriber = simplenews_subscriber_load($snid);
if (!empty($subscriber) && $subscriber->snid == $snid) {
$record = new stdClass();
$record->snid = $subscriber->snid;
$record->nid = $nid;
$record->timestamp = time();
drupal_write_record('simplenews_statistics_open', $record);
}
}
if ($terminate == FALSE) {
return;
// Allow PHP execution to continue.
}
// Render a transparent image and stop PHP execution.
$type = 'image/png; utf-8';
$file = drupal_get_path('module', 'simplenews_statistics') . '/images/count.png';
// Default headers are set by drupal_page_header(), just set content type.
drupal_add_http_header('Content-Type', $type);
drupal_add_http_header('Content-Length', filesize($file));
readfile($file);
drupal_exit();
}