function subscriptions_content_node_form in Subscriptions 6
Same name and namespace in other branches
- 5.2 subscriptions_content.module \subscriptions_content_node_form()
Build the Thread subscriptions form at user/UID/subscriptions/node.
1 string reference to 'subscriptions_content_node_form'
- subscriptions_content_page_node in ./
subscriptions_content.module - Subscriptions page callback: List thread subscriptions.
File
- ./
subscriptions_content.module, line 845 - Subscriptions to content events
Code
function subscriptions_content_node_form(&$form_state, $account, $form) {
$uid = $account->uid;
$tr = 't';
$subscriptions = array();
$sql = db_rewrite_sql("\n SELECT n.nid, n.uid, s.send_interval, s.author_uid, s.send_comments, s.send_updates, n.title, n.status, n.changed, n.comment AS comment_count, ncs.last_comment_timestamp,\n CASE WHEN s.send_comments + s.send_updates = 0 THEN n.created\n WHEN s.send_comments + s.send_updates = 2 THEN\n CASE WHEN n.changed > ncs.last_comment_timestamp THEN n.changed ELSE ncs.last_comment_timestamp END\n WHEN s.send_comments = 1 THEN ncs.last_comment_timestamp\n ELSE n.changed END\n AS latest_activity\n FROM {node} n\n INNER JOIN {subscriptions} s ON " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "n.nid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " = s.value\n LEFT JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid\n WHERE s.module = 'node' AND s.field = 'nid' AND s.recipient_uid = %d\n ORDER BY latest_activity DESC");
$sql_count = db_rewrite_sql("\n SELECT COUNT(n.nid)\n FROM {node} n\n INNER JOIN {subscriptions} s ON " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "n.nid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " = s.value\n WHERE s.module = 'node' AND s.field = 'nid' AND s.recipient_uid = %d");
$result = pager_query($sql, 50, 0, $sql_count, $uid);
while ($s = db_fetch_array($result)) {
$subscriptions[$s['nid']][$s['author_uid']] = $s;
}
// check whether we've commented:
$nids = array_keys($subscriptions);
$result = db_query("\n SELECT nid FROM {comments}\n WHERE\n nid IN (\n SELECT " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "value" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS INTEGER)' : '') . " FROM {subscriptions} WHERE module = 'node' AND field = 'nid' AND recipient_uid = %d\n )\n AND uid = %d GROUP BY nid", $uid, $uid);
while ($c = db_fetch_array($result)) {
if (isset($subscriptions[$c['nid']])) {
foreach ($subscriptions[$c['nid']] as $author_uid => $subscription) {
$subscriptions[$c['nid']][$author_uid]['commented'] = TRUE;
}
}
}
$form[0] = array(
'#type' => 'item',
'#title' => '',
'#tree' => TRUE,
'#theme' => 'subscriptions_form_table',
);
$defaults = array();
foreach ($subscriptions as $nid => $bundle) {
foreach ($bundle as $author_uid => $subscription) {
$title = truncate_utf8($subscription['title'], 40);
if ($title != $subscription['title']) {
$title .= '...';
}
$title = l($title, 'node/' . $subscription['nid']);
if (!$subscription['status']) {
if (user_access('administer nodes')) {
$title = SUBSCRIPTIONS_UNAVAILABLE . ' ' . $title;
}
else {
continue;
}
}
$subscription['extra_info'] = t('@latest_activity, @authored, @commented', array(
'@latest_activity' => format_interval(time() - $subscription['latest_activity']),
'@authored' => $subscription['uid'] == $uid ? $tr('Yes') : $tr('No'),
'@commented' => !empty($subscription['commented']) ? $tr('Yes') : $tr('No'),
));
subscriptions_form_helper($form[0], $defaults, $author_uid, $subscription['nid'], $title, $subscription);
}
}
unset($form[0]['author']);
if (count(element_children($form[0]))) {
$form[0]['extra_info']['#title'] = t('Latest activity, authored, commented');
$form[0]['defaults'] = array(
'#type' => 'value',
'#value' => $defaults,
);
subscriptions_form_column_filter($form[0], $uid);
$form['#tree'] = TRUE;
$form['uid'] = array(
'#type' => 'value',
'#value' => $uid,
);
$form['access_key'] = array(
'#type' => 'value',
'#value' => 'node',
);
$form['module'] = array(
'#type' => 'value',
'#value' => 'node',
);
$form['field'] = array(
'#type' => 'value',
'#value' => 'nid',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 10,
);
$form['#submit'][] = 'subscriptions_page_form_submit';
$form['note'] = array(
'#type' => 'item',
'#description' => '<div>' . t('Note: Deactivated subscriptions will be removed from the list.') . '</div>',
);
$form['pager'] = array(
'#value' => theme('pager', NULL, 50, 0),
);
}
else {
unset($form['header']);
unset($form['footer']);
$form['notice'] = array(
'#type' => 'item',
'#value' => t('There are no subscribed pages.'),
'#weight' => 10,
);
}
return $form;
}