/[drupal]/contributions/modules/weblinks/weblinks.user.inc
ViewVC logotype

Contents of /contributions/modules/weblinks/weblinks.user.inc

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


Revision 1.3 - (show annotations) (download) (as text)
Mon Jul 20 16:52:34 2009 UTC (4 months, 1 week ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +53 -263 lines
File MIME type: text/x-php
Update HEAD to start 7.x
1 <?php
2 // $Id: weblinks.user.inc,v 1.2.2.13.2.3 2009/07/11 17:37:33 nancyw Exp $
3 /**
4 * @file
5 * Displays a Drupal page containing weblinks submitted by a given user.
6 */
7 function weblinks_user_page($account) {
8 $save_hp = $account->homepage;
9 unset($account->homepage);
10 $trail = array(l(t('Home'), ''), theme('username', $account, array('levels' => FALSE)));
11 $account->homepage = $save_hp;
12 drupal_set_breadcrumb($trail);
13
14 $output = drupal_get_form('weblinks_user_form', $account);
15 return $output;
16 }
17
18 function _weblinks_user_access_check($user, $account) {
19 if (user_access('edit own weblinks', $user) && ($account->uid == $user->uid)) {
20 return TRUE;
21 }
22 return user_access('administer weblinks', $user);
23 }
24
25 function weblinks_user_form($form_state, $account) {
26 global $user;
27 $vocid = _weblinks_get_vocid();
28 // If $vocid is not empty, we know that the taxonomy module is available.
29 $taxo = !empty($vocid);
30 $unclassed = _weblinks_unclassed();
31 $destination = drupal_get_destination();
32 $options = array();
33 $now = $_SERVER['REQUEST_TIME'];
34 $limit = 20;
35 $node_ops = module_invoke_all('node_operations');
36
37 $query = db_rewrite_sql("SELECT n.* FROM {node} n WHERE n.uid=%d AND n.type='weblinks' ORDER BY n.changed DESC");
38 $result = pager_query($query, $limit, 0, NULL, $account->uid);
39 while ($node = db_fetch_object($result)) {
40 $status = array();
41 $status[] = $node->status ? t('published') : t('not published');
42 if ($node->promoted) {
43 $status[] = t('promoted');
44 }
45 if ($node->sticky > 0) { // >0 allows for sticky-encoded weighting.
46 $status[] = t('sticky');
47 }
48 if ($node->moderated) {
49 $status[] = t('moderated');
50 }
51 $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
52 $form['status'][$node->nid] = array('#value' => implode(', ', $status));
53 $form['update'][$node->nid] = array('#value' => format_interval($now - $node->changed));
54
55 $tid_list = array();
56 if ($taxo) {
57 $terms = db_query("SELECT tn.tid, td.name FROM {term_node} tn LEFT JOIN {term_data} td USING (tid) WHERE tn.nid=%d AND tn.vid=%d", $node->nid, $node->vid);
58 while ($row = db_fetch_array($terms)) {
59 $tid_list[] = check_plain($row['name'] ? $row['name'] : $unclassed->name);
60 }
61 }
62 $form['group'][$node->nid] = array('#value' => implode(', ', $tid_list));
63
64 if (_weblinks_user_access_check($user, $account)) {
65 $form['operationse'][$node->nid] = array('#value' => l(t('edit'), 'node/'. $node->nid .'/edit', array('query' => $destination)));
66 $form['operationsd'][$node->nid] = array('#value' => l(t('delete'), 'node/'. $node->nid .'/delete', array('query' => $destination)));
67 }
68 }
69 $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
70
71 return $form;
72 }
73
74 /**
75 * Theme node administration overview.
76 */
77 function theme_weblinks_user_form($form) {
78 // Overview table:
79 $header = array(t('Title'), t('Status'), t('Group'), t('Last updated'), array('data' => t('Operations'), 'colspan' => '2'));
80 $rows =array();
81
82 if (isset($form['title']) && is_array($form['title'])) {
83 foreach (element_children($form['title']) as $key) {
84 $rows[] = array(
85 drupal_render($form['title'][$key]),
86 drupal_render($form['status'][$key]),
87 drupal_render($form['group'][$key]),
88 drupal_render($form['update'][$key]),
89 drupal_render($form['operationse'][$key]),
90 drupal_render($form['operationsd'][$key]),
91 );
92 }
93 }
94 else {
95 $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
96 }
97 $output .= theme('table', $header, $rows);
98 if ($form['pager']['#value']) {
99 $output .= drupal_render($form['pager']);
100 }
101 $output .= drupal_render($form);
102 return $output;
103 }
104

  ViewVC Help
Powered by ViewVC 1.1.2