| 1 |
<?php
|
| 2 |
// $Id: subscriptions_blog_ui.module,v 1.6 2009/02/12 15:26:56 salvis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Provide a Subscriptions UI for the blog content type subscriptions
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_subscriptions().
|
| 11 |
*
|
| 12 |
* @ingroup hooks
|
| 13 |
*/
|
| 14 |
function subscriptions_blog_ui_subscriptions($op, $arg0 = NULL, $arg1 = NULL, $arg2 = NULL) {
|
| 15 |
$function = '_subscriptions_blog_ui_'. $op;
|
| 16 |
if (function_exists($function)) {
|
| 17 |
return $function($arg0, $arg1, $arg2);
|
| 18 |
}
|
| 19 |
if ($op == 'stype' && $arg0 == 'blog') {
|
| 20 |
return array('node', 'type', 'blog', $arg1);
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Implementation of hook_types(), subhook of hook_subscriptions().
|
| 26 |
*
|
| 27 |
* This is called by subscriptions_types() in subscriptions.module.
|
| 28 |
*
|
| 29 |
* @return
|
| 30 |
* Returns information about types for the Subscriptions module interface.
|
| 31 |
*
|
| 32 |
* @ingroup form
|
| 33 |
* @ingroup hooks
|
| 34 |
*
|
| 35 |
* @see subscriptions_types()
|
| 36 |
*/
|
| 37 |
function _subscriptions_blog_ui_types() {
|
| 38 |
$tr = 't';
|
| 39 |
$types['blog'] = array(
|
| 40 |
'title' => $tr('Blogs'),
|
| 41 |
'access' => 'subscribe to blogs',
|
| 42 |
'page' => 'subscriptions_blog_ui_page_blog',
|
| 43 |
'fields' => array('blog', 'author_uid'),
|
| 44 |
'weight' => -3,
|
| 45 |
);
|
| 46 |
return $types;
|
| 47 |
t('subscribe to blogs');
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Returns a list of blog subscriptions.
|
| 52 |
*
|
| 53 |
* @ingroup form
|
| 54 |
*/
|
| 55 |
function subscriptions_blog_ui_page_blog($account, $form) {
|
| 56 |
$blogs = array();
|
| 57 |
// get the blogs
|
| 58 |
$sql = db_rewrite_sql("
|
| 59 |
SELECT u.uid, u.name
|
| 60 |
FROM {node} n
|
| 61 |
INNER JOIN {users} u ON n.uid = u.uid
|
| 62 |
WHERE n.type = 'blog' AND n.status = 1
|
| 63 |
GROUP BY u.uid, u.name
|
| 64 |
ORDER BY u.name");
|
| 65 |
$result = db_query($sql);
|
| 66 |
while ($usr = db_fetch_array($result)) {
|
| 67 |
$blogs[$usr['uid']] = array(
|
| 68 |
'uid' => $usr['uid'],
|
| 69 |
'name' => $usr['name'],
|
| 70 |
'has_blog' => TRUE,
|
| 71 |
);
|
| 72 |
}
|
| 73 |
|
| 74 |
// possibly additional blog subscription entries (no blog nodes)
|
| 75 |
if (isset($account)) {
|
| 76 |
$result = db_query("
|
| 77 |
SELECT s.author_uid, u.name
|
| 78 |
FROM {subscriptions} s
|
| 79 |
INNER JOIN {users} u ON s.author_uid = u.uid
|
| 80 |
WHERE s.module = 'node' AND s.field = 'type' AND s.value = 'blog' AND s.recipient_uid = %d
|
| 81 |
ORDER BY u.name", $account->uid);
|
| 82 |
while ($usr = db_fetch_array($result)) {
|
| 83 |
$blogs[$usr['author_uid']]['uid'] = $usr['author_uid'];
|
| 84 |
$blogs[$usr['author_uid']]['name'] = $usr['name'];
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
if (!empty($blogs)) {
|
| 89 |
return drupal_get_form('subscriptions_blog_ui_blog_form', $blogs, $account, $form);
|
| 90 |
}
|
| 91 |
else {
|
| 92 |
return t('There are no active blogs.');
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Returns the blog subscription form.
|
| 98 |
*
|
| 99 |
* @ingroup form
|
| 100 |
*/
|
| 101 |
function subscriptions_blog_ui_blog_form(&$form_state, $blogs, $account, $form) {
|
| 102 |
$uid = (isset($account) ? $account->uid : (is_numeric(arg(5)) ? -arg(5) : -DRUPAL_AUTHENTICATED_RID));
|
| 103 |
$subscriptions = array();
|
| 104 |
$result = db_query("
|
| 105 |
SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, u.name
|
| 106 |
FROM {subscriptions} s
|
| 107 |
INNER JOIN {users} u ON s.author_uid = u.uid
|
| 108 |
WHERE s.module = 'node' AND s.field = 'type' AND s.value = 'blog' AND s.recipient_uid = %d
|
| 109 |
ORDER BY u.name", $uid);
|
| 110 |
while ($s = db_fetch_array($result)) {
|
| 111 |
$subscriptions[$s['author_uid']] = $s;
|
| 112 |
}
|
| 113 |
$form[0] = array(
|
| 114 |
'#type' => 'item',
|
| 115 |
'#title' => '',
|
| 116 |
'#tree' => TRUE,
|
| 117 |
'#theme' => 'subscriptions_form_table',
|
| 118 |
);
|
| 119 |
|
| 120 |
$intervals = _subscriptions_send_intervals();
|
| 121 |
foreach ($blogs as $blog) {
|
| 122 |
$title = ($blog['has_blog'] ? l($blog['name'], 'blog/'. $blog['uid']) : $blog['name']);
|
| 123 |
// add the active subscriptions
|
| 124 |
if (!isset($subscriptions[$blog['uid']])) {
|
| 125 |
// author-less item is missing -- add it here:
|
| 126 |
$subscriptions[$blog['uid']] = array(
|
| 127 |
'send_interval' => _subscriptions_get_setting('send_interval', ($uid < 0 ? $uid : $account)),
|
| 128 |
'send_comments' => _subscriptions_get_setting('send_comments', ($uid < 0 ? $uid : $account)),
|
| 129 |
'send_updates' => _subscriptions_get_setting('send_updates', ($uid < 0 ? $uid : $account)),
|
| 130 |
);
|
| 131 |
}
|
| 132 |
subscriptions_form_helper($form[0], $defaults, $blog['uid'], 'blog', $title, $subscriptions[$blog['uid']]);
|
| 133 |
}
|
| 134 |
unset($form[0]['author']);
|
| 135 |
$form[0]['defaults'] = array(
|
| 136 |
'#type' => 'value',
|
| 137 |
'#value' => $defaults,
|
| 138 |
);
|
| 139 |
subscriptions_form_column_filter($form[0], $uid);
|
| 140 |
|
| 141 |
$form['#tree'] = TRUE;
|
| 142 |
$form['uid'] = array('#type' => 'value', '#value' => $uid);
|
| 143 |
$form['access_key'] = array('#type' => 'value', '#value' => 'blog');
|
| 144 |
$form['module'] = array('#type' => 'value', '#value' => 'node');
|
| 145 |
$form['field'] = array('#type' => 'value', '#value' => 'type');
|
| 146 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#weight' => 10);
|
| 147 |
$form['#submit'][] = 'subscriptions_page_form_submit';
|
| 148 |
return $form;
|
| 149 |
}
|
| 150 |
|
| 151 |
/**
|
| 152 |
* Implementation of hook_count_user_subscriptions().
|
| 153 |
*
|
| 154 |
* @ingroup hooks
|
| 155 |
*/
|
| 156 |
function subscriptions_blog_ui_count_user_subscriptions($counts, $uid) {
|
| 157 |
$counts['blog']['author_uid'] = db_result(db_query("SELECT count(*) FROM {subscriptions} WHERE module = 'node' AND field = 'type' AND value = 'blog' AND recipient_uid = %d", $uid));
|
| 158 |
return $counts;
|
| 159 |
}
|