/[drupal]/contributions/modules/profile_blog_info/profile_blog_info.module
ViewVC logotype

Contents of /contributions/modules/profile_blog_info/profile_blog_info.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Tue Dec 16 01:25:26 2008 UTC (11 months, 1 week ago) by mfer
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -2 lines
File MIME type: text/x-php
#309589: Fixed issue where RSS field title could not be changed.
#318080: Fixed schema. Removed unneeded default => ''
1 <?php
2 // $Id: profile_blog_info.module,v 1.3 2008/08/05 23:26:39 mfer Exp $
3
4 /**
5 * @file
6 * Provides a blog url, blog title, and RSS feed url for Profiles. The RSS feeds are managed by the Aggregator module.
7 *
8 * Adds a RSS field to the profile page for users to enter blogs feeds, etc. Aggregator manages
9 * RSS fields so they can be placed in blocks or any way aggregator can display or manage them.
10 */
11
12 /**
13 * Implementation of hook_menu().
14 */
15 function profile_blog_info_menu() {
16 $items = array();
17
18 $items['admin/user/profile_blog_info'] = array(
19 'title' => 'Profiles Blog Information',
20 'description' => 'Add a blog fields to profiles.',
21 'page callback' => 'drupal_get_form',
22 'page arguments' => array('profile_blog_info_admin_form'),
23 'access arguments' => array('administer users'),
24 'file' => 'profile_blog_info.forms.inc',
25 );
26
27 return $items;
28 }
29
30 /**
31 * Implementation of hook_user().
32 */
33 function profile_blog_info_user($op, &$edit, &$user, $category = NULL) {
34 switch ($op) {
35 case 'load':
36 return profile_blog_info_load_profile($user);
37 case 'register':
38 return profile_blog_info_form_profile($edit, $user, $category, TRUE);
39 case 'update':
40 return profile_blog_info_save_profile($edit, $user, $category);
41 case 'insert':
42 return profile_blog_info_save_profile($edit, $user, $category);
43 case 'view':
44 return profile_blog_info_view_profile($user);
45 case 'form':
46 return profile_blog_info_form_profile($edit, $user, $category);
47 case 'validate':
48 return profile_blog_info_validate_profile($edit, $category);
49 case 'categories':
50 return profile_blog_info_categories();
51 case 'delete':
52 $f = db_fetch_array(db_query('SELECT fid FROM {profile_blog_info} WHERE uid = %d', $user->uid));
53 profile_blog_info_save_feed($f);
54 db_query('DELETE FROM {profile_blog_info} WHERE uid = %d', $user->uid);
55 }
56 }
57
58 function profile_blog_info_load_profile(&$user) {
59
60 $f = db_fetch_array(db_query('SELECT fid, blog_url FROM {profile_blog_info} WHERE uid = %d', $user->uid));
61
62 if (empty($user->profile_blog_info) && isset($f['fid'])) {
63 $feed = aggregator_feed_load($fid);
64 if (!empty($feed)) {
65 $user->profile_blog_info = $feed['url'];
66 $user->profile_blog_info_title = $feed['title'];
67 }
68 }
69 if (empty($user->profile_blog_info_blog_url) && !empty($f['blog_url'])) {
70 $user->profile_blog_info_blog_url = $f['blog_url'];
71 }
72 }
73
74 function profile_blog_info_form_profile($edit, $user, $category, $register = FALSE) {
75
76 if ($register == FALSE || ($register == TRUE && variable_get('profile_blog_info_register', 0) == 1)) {
77 $rss_category = variable_get('profile_blog_info_profile_category', 'account') ? variable_get('profile_blog_info_profile_category', 'account') : 'account';
78
79 if ($rss_category == $category || $register == TRUE) {
80
81 $form['profile_blog_info_fieldset'] = array('#type' => 'fieldset', '#title' => variable_get('profile_blog_info_fieldset', t('Blog Information')), '#weight' => 1);
82 $form['profile_blog_info_fieldset']['profile_blog_info_title'] = array(
83 '#type' => 'textfield',
84 '#title' => variable_get('profile_blog_info_title', t('Title')),
85 '#default_value' => $user->profile_blog_info_title ? $user->profile_blog_info_title : '',
86 '#required' => variable_get('profile_blog_info_required', 0) ? TRUE : FALSE,
87 '#weight' => 3.00000000001,
88 );
89 $form['profile_blog_info_fieldset']['profile_blog_info_blog_url'] = array(
90 '#type' => 'textfield',
91 '#title' => variable_get('profile_blog_info_blog', t('Blog or homepage')),
92 '#default_value' => $user->profile_blog_info_blog_url ? $user->profile_blog_info_blog_url : '',
93 '#required' => variable_get('profile_blog_info_required', 0) ? TRUE : FALSE,
94 '#weight' => 3.00000000002,
95 );
96 $form['profile_blog_info_fieldset']['profile_blog_info'] = array(
97 '#type' => 'textfield',
98 '#title' => variable_get('profile_blog_info_rss', t('RSS')),
99 '#default_value' => $user->profile_blog_info ? $user->profile_blog_info : '',
100 '#required' => variable_get('profile_blog_info_required', 0) ? TRUE : FALSE,
101 '#weight' => 3.00000000003,
102 '#description' => variable_get('profile_blog_info_explanation', ''),
103 );
104 }
105 }
106 return $form;
107 }
108
109 function profile_blog_info_categories() {
110 $data = array();
111 $category = variable_get('profile_blog_info_profile_category', '');
112 if (!empty($category)) {
113 $data[] = array(
114 'name' => $category,
115 'title' => $category,
116 'weight' => 3,
117 );
118 }
119 return $data;
120 }
121
122 function profile_blog_info_view_profile(&$user) {
123 $category = variable_get('profile_blog_info_profile_category', '');
124 if (!empty($user->profile_blog_info_blog_url)&& !empty($user->profile_blog_info_title)) {
125 $user->content['summary']['profile_blog_info_title'] = array(
126 '#type' => 'user_profile_item',
127 '#value' => l($user->profile_blog_info_title, $user->profile_blog_info_blog_url),
128 );
129 }
130 }
131
132 function profile_blog_info_validate_profile($edit, $category) {
133
134 if ($category == variable_get('profile_blog_info_profile_category', 'account') || variable_get('profile_blog_info_profile_category', '') == '') {
135
136 if (!valid_url($edit['profile_blog_info_blog_url'], TRUE) && !empty($edit['profile_blog_info_blog_url'])) {
137 form_set_error('url', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $edit['profile_blog_info_blog_url'])));
138 }
139
140 if (!valid_url($edit['profile_blog_info'], TRUE) && !empty($edit['profile_blog_info'])) {
141 form_set_error('url', t('The URL %url is invalid. Please enter a fully-qualified URL, such as http://www.example.com/feed.xml.', array('%url' => $edit['profile_blog_info'])));
142 }
143
144 if ($edit['profile_blog_info'] XOR $edit['profile_blog_info_title']) {
145 form_set_error('url', t('Please fill in both the %title and the %url.', array('%title' => variable_get('profile_blog_info_title', t('Title')), '%url' => variable_get('profile_blog_info', t('RSS')))));
146 }
147 }
148 }
149
150 function profile_blog_info_save_profile($edit, $user, $category) {
151 if ($fid = db_result(db_query('SELECT fid FROM {profile_blog_info} WHERE uid = %d', $user->uid))) {
152 $feed = aggregator_feed_load($fid);
153 }
154 else {
155 $feed['refresh'] = variable_get('profile_blog_info_refresh', 900);
156 $feed['category'] = variable_get('profile_blog_info_category', array());
157 }
158
159 $feed['title'] = $edit['profile_blog_info_title'];
160 $feed['url'] = $edit['profile_blog_info'];
161
162 $fid = profile_blog_info_save_feed($feed);
163
164 if (!empty($fid)) {
165 if (!empty($feed['fid'])) {
166 db_query("UPDATE {profile_blog_info} SET fid = %d, blog_url = '%s' WHERE uid = %d", $fid, $edit['profile_blog_info_blog_url'], $user->uid);
167 }
168 else {
169 db_query("INSERT INTO {profile_blog_info} (fid, uid, blog_url) VALUES (%d, %d, '%s')", $fid, $user->uid, $edit['profile_blog_info_blog_url']);
170 }
171 }
172 }
173
174 function profile_blog_info_save_feed($edit) {
175 if (!empty($edit['fid'])) {
176 // An existing feed is being modified, delete the category listings.
177 db_query('DELETE FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
178 }
179 if (!empty($edit['fid']) && !empty($edit['title'])) {
180 db_query("UPDATE {aggregator_feed} SET title = '%s', url = '%s', refresh = %d WHERE fid = %d", $edit['title'], $edit['url'], $edit['refresh'], $edit['fid']);
181 }
182 else if (!empty($edit['fid'])) {
183 $items = array();
184 $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
185 while ($item = db_fetch_object($result)) {
186 $items[] = "iid = $item->iid";
187 }
188 if (!empty($items)) {
189 db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', $items));
190 }
191 db_query('DELETE FROM {aggregator_feed} WHERE fid = %d', $edit['fid']);
192 db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $edit['fid']);
193 }
194 else if (!empty($edit['title'])) {
195 db_query("INSERT INTO {aggregator_feed} (title, url, refresh, block, description, image) VALUES ('%s', '%s', %d, 5, '', '')", $edit['title'], $edit['url'], $edit['refresh']);
196 // A single unique id for bundles and feeds, to use in blocks.
197 $edit['fid'] = db_last_insert_id('aggregator_feed', 'fid');
198 }
199 if (!empty($edit['title'])) {
200 // The feed is being saved, save the categories as well.
201 if (!empty($edit['category'])) {
202 foreach ($edit['category'] as $cid => $value) {
203 if ($value) {
204 db_query('INSERT INTO {aggregator_category_feed} (fid, cid) VALUES (%d, %d)', $edit['fid'], $cid);
205 }
206 }
207 }
208 }
209 return $edit['fid'];
210 }

  ViewVC Help
Powered by ViewVC 1.1.2