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

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

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


Revision 1.3 - (show annotations) (download) (as text)
Mon Sep 7 18:26:23 2009 UTC (2 months, 2 weeks ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +25 -6 lines
File MIME type: text/x-php
Latest from Charles Mattice.
1 <?php
2 // $Id: quotes.user.inc,v 1.2 2009/08/28 16:28:01 nancyw Exp $
3 /**
4 * @file
5 * Displays a Drupal page containing quotes submitted by a given user.
6 */
7 function quotes_user_page($account) {
8 $save_hp = $account->homepage;
9 unset($account->homepage);
10 $trail = array(l(t('Home'), ''), theme('username', $account));
11 $account->homepage = $save_hp;
12 drupal_set_breadcrumb($trail);
13
14 $output = drupal_get_form('quotes_user_form', $account);
15 return $output;
16 }
17
18 /*
19 * hook_access removed in favor of hook_node_access
20 *
21 * function _quotes_user_form_access($user, $account) {
22 * if (user_access('edit own quotes', $user) && ($account->uid == $user->uid)) {
23 * return TRUE;
24 * }
25 * return user_access('administer quotes', $user);
26 * }
27 */
28
29 function _quotes_user_form_node_access($node, $op, $account) {
30 $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
31
32 if (in_array($type, nodeperms_get_configured_types())) {
33 if ($op == 'update') {
34 if (user_access('edit own quotes', $user) && ($account->uid == $user->uid)) {
35 return NODE_ACCESS_ALLOW;
36 }
37 }
38 }
39
40 // Returning nothing from this function would have the same effect.
41 return NODE_ACCESS_IGNORE;
42 }
43
44 function quotes_user_form($form_state, $account) {
45 global $user;
46 $destination = drupal_get_destination();
47 $options = array();
48 $now = $_SERVER['REQUEST_TIME'];
49 $limit = variable_get('quotes_per_page', 10);
50 $node_ops = module_invoke_all('node_operations');
51
52 //$query = db_rewrite_sql("SELECT n.* FROM {node} n WHERE n.uid=%d AND n.type='quotes' ORDER BY n.changed DESC");
53 $query = db_select('node', 'n');
54 $query
55 ->fields('n', array('nid'))
56 ->condition("n.uid", $user->uid)
57 ->condition("n.type", 'quotes')
58 ->orderby('n.changed', 'DESC')
59 ->range(0, $limit);
60 $query->addTag('node_access');
61 $result = $query->execute();
62 //$result = pager_query($query, $limit, 0, NULL, $account->uid);
63 while ($node = db_fetch_object($result)) {
64 $status = array();
65 $status[] = $node->status ? t('published') : t('not published');
66 if ($node->promoted) {
67 $status[] = t('promoted');
68 }
69 if ($node->sticky > 0) { // >0 allows for sticky-encoded weighting.
70 $status[] = t('sticky');
71 }
72 if ($node->moderated) {
73 $status[] = t('moderated');
74 }
75 $form['title'][$node->nid] = array('#value' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', node_mark($node->nid, $node->changed)));
76 $form['status'][$node->nid] = array('#value' => implode(', ', $status));
77 $form['updated'][$node->nid] = array('#value' => format_interval($now - $node->changed));
78
79 $tid_list = array();
80 $terms = db_query("SELECT tn.tid, td.name FROM {taxonomy_term_node} tn LEFT JOIN {taxonomy_term_data} td USING (tid) WHERE tn.nid=%d AND tn.vid=%d", $node->nid, $node->vid);
81 while ($row = db_fetch_array($terms)) {
82 $tid_list[] = check_plain($row['name']);
83 }
84 $form['group'][$node->nid] = array('#value' => implode(', ', $tid_list));
85
86 if (_quotes_user_form_node_access($user, $account)) {
87 $form['operationse'][$node->nid] = array('#value' => l(t('edit'), 'node/' . $node->nid . '/edit', array('query' => $destination)));
88 $form['operationsd'][$node->nid] = array('#value' => l(t('delete'), 'node/' . $node->nid . '/delete', array('query' => $destination)));
89 }
90 }
91 $form['pager'] = array('#value' => theme('pager', NULL, $limit, 0));
92
93 return $form;
94 }
95
96 /**
97 * Theme node administration overview.
98 */
99 function theme_quotes_user_form($form) {
100 // Overview table:
101 $header = array(t('Title'), t('Status'), t('Tags'), t('Last updated'), array('data' => t('Operations'), 'colspan' => '2'));
102 $rows =array();
103
104 if (isset($form['title']) && is_array($form['title'])) {
105 foreach (element_children($form['title']) as $key) {
106 $rows[] = array(
107 drupal_render($form['title'][$key]),
108 drupal_render($form['status'][$key]),
109 drupal_render($form['group'][$key]),
110 drupal_render($form['updated'][$key]),
111 drupal_render($form['operationse'][$key]),
112 drupal_render($form['operationsd'][$key]),
113 );
114 }
115 }
116 else {
117 $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
118 }
119 $output .= theme('table', $header, $rows);
120 if ($form['pager']['#value']) {
121 $output .= drupal_render($form['pager']);
122 }
123 $output .= drupal_render($form);
124 return $output;
125 }
126

  ViewVC Help
Powered by ViewVC 1.1.2