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

Contents of /contributions/modules/advanced_profile/advanced_profile.module

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


Revision 1.26 - (show annotations) (download) (as text)
Tue Dec 16 04:37:44 2008 UTC (11 months, 1 week ago) by michellec
Branch: MAIN
CVS Tags: DRUPAL-5--1-0-BETA1, HEAD
Branch point for: DRUPAL-6--1, DRUPAL-5
Changes since 1.25: +45 -16 lines
File MIME type: text/x-php
NOISSUE by Michelle: Fixed missing order on profile visits that was causing it to show the oldest visits.
NOISSUE by Michelle: Code clean up and comments.
NOISSUE by Michelle: Added options for image directory and interval granularity.
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Provides building blocks for creating enhanced user profile pages.
7 */
8
9 // DRUPAL HOOKS **************************************************************/
10
11 /**
12 * Implementation of hook_perm().
13 */
14 function advanced_profile_perm() {
15 return array('administer advanced profile');
16 }
17
18 /**
19 * Implementation of hook_menu().
20 */
21 function advanced_profile_menu($may_cache) {
22 $items = array();
23 if ($may_cache) {
24 // Add menu entry for settings page
25 $items[] = array(
26 'path' => "admin/settings/advanced-profile",
27 'title' => t('Advanced Profile'),
28 'callback' => 'drupal_get_form',
29 'callback arguments' => array('advanced_profile_settings_page'),
30 'access' => user_access('administer advanced profile'),
31 );
32 }
33 elseif (arg(0) == 'user' && arg(2) == '') {
34 advanced_profile_add_css();
35 }
36 return $items;
37 }
38
39 // SETTINGS ****************************************************************/
40
41 /**
42 * Define settings form
43 */
44 function advanced_profile_settings_page() {
45 // Choose image directory.
46 $form['advanced_profile_image_directory'] = array(
47 '#type' => 'textfield',
48 '#title' => t('Image directory'),
49 '#size' => 50,
50 '#description' => t('Path from active theme to image directory. If left blank the images in the module directory will be used.'),
51 '#default_value' => variable_get('advanced_profile_image_directory', ''),
52 );
53
54 // Interval granularity.
55 $form['advanced_profile_visits_interval_granularity'] = array(
56 '#type' => 'textfield',
57 '#title' => t('Granularity of time ago to use on profile visits listing'),
58 '#size' => 10,
59 '#default_value' => variable_get('advanced_profile_visits_interval_granularity', 2),
60 '#description' => t('1 gives you "1 hour ago". 2 gives you "1 hour 4 minutes ago". 3 gives you "1 hour 4 minutes and 2 seconds ago"'),
61 );
62
63 // Check if uprofile type exists.
64 $uprofile_exists = db_result(db_query("SELECT count(type) FROM {node_type} WHERE type='%s'", 'uprofile'));
65 $ccopy_installed = module_exists('content_copy');
66
67 // Auto create uprofile type option
68 $form['advanced_profile_node_type_setup'] = array(
69 '#type' => 'checkboxes',
70 '#title' => t('Profile type auto creation'),
71 '#options' => array(
72 'Create' => t('Create the user profile node type with included fields'),
73 ),
74 '#description' => t("If you'd like to auto create the node type for user profiles, check this. The option will be disabled if you have a uprofile node type or do not have content copy (from CCK) enabled."),
75 '#disabled' => $uprofile_exists || !$ccopy_installed,
76 );
77
78 // Create the uprofile content type if requested by the user checking the box
79 $node_type_setup = variable_get('advanced_profile_node_type_setup', 0);
80 if ($node_type_setup['Create']) {
81 $cck_definition_file = drupal_get_path('module', 'advanced_profile') . '/includes/uprofile.inc';
82 _create_content_type($cck_definition_file);
83 }
84
85 // Dump the checkbox vars to make sure we don't try to run this more than once
86 variable_del('advanced_profile_node_type_setup');
87
88 // Send our form to Drupal to make a settings page
89 return system_settings_form($form);
90 }
91
92 // PANELS ********************************************************************/
93 if (module_exists('panels')) {
94 include_once drupal_get_path('module', 'advanced_profile') . '/includes/panels.inc';
95 }
96
97 // VIEWS *********************************************************************/
98 if (module_exists('views')) {
99 include_once drupal_get_path('module', 'advanced_profile') . '/includes/views.inc';
100 }
101
102 // THEME *********************************************************************/
103 include_once drupal_get_path('module', 'advanced_profile') . '/includes/theme.inc';
104
105 /**
106 * Returns the path to the images used by this module.
107 */
108 function advanced_profile_path_to_images() {
109 $image_directory = variable_get('advanced_profile_image_directory', '');
110 if (!empty($image_directory)) {
111 $image_directory = path_to_theme() . '/' . $image_directory;
112 }
113 else {
114 $image_directory = drupal_get_path('module', 'advanced_profile') . '/images';
115 }
116
117 return $image_directory;
118 }
119
120 /**
121 * Adds the needed CSS.
122 */
123 function advanced_profile_add_css() {
124 // Find the CSS file by looking first in the theme and then in the module.
125 $css_file = path_to_theme() . '/advanced_profile.css';
126
127 if (!file_exists($css_file)) {
128 $css_file = drupal_get_path('module', 'advanced_profile') . '/theme/advanced_profile.css';
129 }
130
131 drupal_add_css($css_file);
132 }
133
134 // OUTSIDE MODULE INTEGRATION ************************************************/
135 include_once drupal_get_path('module', 'advanced_profile') . '/includes/integration.inc';
136
137 // GENERAL FUNCTIONS *********************************************************/
138
139 /**
140 * This function is no longer used but is kept to avoid errors from people
141 * who have the call in their template.php from using earlier versions.
142 */
143 function advanced_profile_addvars($hook, $vars) {
144 return $vars;
145 }
146
147 /**
148 * Returns recent visits to a profile page excluding that user and anonymous.
149 */
150 function advanced_profile_tracker($uid) {
151 if (module_exists('statistics')) {
152 $interval_granularity = variable_get('advanced_profile_visits_interval_granularity', 2);
153 if (empty($uid)) {
154 $uid = arg(1);
155 }
156
157 $result = db_query_range('SELECT a.timestamp, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE a.uid <> %d AND a.uid > 0 AND a.path LIKE \'user/%d%%\' ORDER BY a.timestamp DESC', $uid, $uid, 0, 10);
158
159 $items = array();
160 while ($log = db_fetch_object($result)) {
161 $items[] = theme('username', $log) . " " . format_interval(time() - $log->timestamp, $interval_granularity) . " ago.";
162 }
163
164 return $items;
165 }
166
167 return -1;
168 }
169
170 /**
171 * Helper function to import a CCK content type definition from a text file.
172 * Thanks Wim Leers
173 *
174 * @param $cck_definition_file
175 * The full path to the file containing the CCK definition.
176 */
177 function _create_content_type($cck_definition_file) {
178 include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');
179 include_once('./'. drupal_get_path('module', 'content') .'/content_admin.inc');
180 $values = array();
181 $values['type_name'] = '<create>';
182 $values['macro'] = file_get_contents($cck_definition_file);
183 drupal_execute("content_copy_import_form", $values);
184 }
185
186

  ViewVC Help
Powered by ViewVC 1.1.2