uid && $op == 'view' && $node->nid && !$teaer) { $node->content['subscriptions'] = array( '#value' => drupal_get_form('subscriptions_ui_form', $node), '#weight' => 100, ); } } function subscriptions_ui_form($node, $account = NULL) { global $user; if (!isset($account)) { $account = $user; } $sql = "SELECT 1 FROM {subscriptions} WHERE module = 'node' AND field = '%s' AND value = '%s' AND author = %d AND recipient_uid = %d"; $key = "node__$node->nid"; $options[$key] = t('Subscribe to comments to this post'); if (db_result(db_query($sql, 'node', 'nid', $node->nid, -1, $account->uid))) { $defaults[] = $key; } $type_name = node_get_types('name', $node->type); $key = "type__$node->type"; $options[$key] = t('To %type posts', array('%type' => $type_name)); if (db_result(db_query($sql, 'node', 'type', $node->type, -1, $account->uid))) { $defaults[] = $key; } $key = 'type__'. $node->type .'__'. $node->uid; $options[$key] = t('Subscribe to %type posts by %name', array('%type' => $type_name, '%name' => $node->name)); if (db_result(db_query($sql, 'node', 'type', $node->type, $node->uid, $account->uid))) { $defaults[] = $key; } foreach ($node->taxonomy as $tid => $term) { $key = "taxa__$tid"; $options[$key] = t('Subscribe to posts in %term.', array('%term' => $term->name)); if (db_result(db_query($sql, 'node', 'tid', $tid, -1, $account->uid))) { $defaults[] = $key; } $key = 'taxa__'. $tid .'__'. $node->uid; $options[$key] = t('Subscribe to posts in %term by %name', array('%term' => $term->name, '%name' => $node->name)); if (db_result(db_query($sql, 'node', 'tid', $tid, $node->uid, $account->uid))) { $defaults[] = $key; } } $form['wrapper'] = array( '#type' => 'fieldset', '#title' => t('Subscribe'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['wrapper']['subscriptions'] = array( '#type' => 'checkboxes', '#options' => $options, ); $form['wrapper']['submit'] = array( '#type' => 'submit', '#value' => t('Subscribe'), ); $form['account'] = array('#type' => 'value', '#value' => $account); return $form; } // TODO: offer the same form in a block to be put in the contents region. function subscriptions_ui_form_submit($form_id, $form_values) { $stypes = module_invoke_all('subscriptions', 'stypes'); $recipient_uid = $form_values['account']->uid; foreach ($form_values['subscriptions'] as $s => $value) { $subscription = explode('__', $s); $stype = $stypes[$subscription[0]]; $args = array($stype[0], $stype[1], $subscription[1], isset($subscription[2]) ? $subscription[2] : -1, $recipient_uid); if ($value) { call_user_func_array('subscriptions_add', $args); } else { db_query("DELETE FROM {subscriptions} WHERE module = '%s' AND field = '%s' AND value = '%s' AND author = %d AND recipient_uid = %d", $args); } } }