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

Contents of /contributions/modules/meez/meez.module

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


Revision 1.5 - (show annotations) (download) (as text)
Fri Oct 10 18:39:32 2008 UTC (13 months, 2 weeks ago) by greggles
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -2 lines
File MIME type: text/x-php
meh - debug code :( - thanks krikette\!
1 <?php
2 // $Id: meez.module,v 1.4 2008/10/10 17:03:20 greggles Exp $
3
4 /**
5 * Implementation of hook_help().
6 */
7 function meez_help($path, $arg) {
8 switch ($path) {
9 case 'admin/help#meez':
10 return t('Allows users to use their meez avatar for your site.');
11 case 'admin/settings/meez':
12 return '<p>'. t('Configure meez.') .'</p>';
13 }
14 }
15
16 /**
17 * Implementation of hook_menu().
18 */
19
20 function meez_menu() {
21 $items = array();
22 $items['admin/settings/meez'] = array(
23 'title' => t('Meez Configuration'),
24 'description' => t('Configure how the Meez module interacts with your site.'),
25 'page callback' => 'drupal_get_form',
26 'page arguments' => array('meez_admin_settings'),
27 'access arguments' => array('administer site configuration'),
28 'type' => MENU_NORMAL_ITEM,
29 );
30
31 return $items;
32 }
33
34
35
36 /**
37 * Implementation of meez_admin_settings form.
38 */
39 function meez_admin_settings() {
40
41 if (user_access('administer site configuration')) {
42 $form["general"]["meez_profile_field"] = array('#type' => 'textfield',
43 '#title' => t('Meez profile field name'), '#size' => 50, '#maxlength' => 50,
44 '#default_value' => variable_get('meez_profile_field', 'profile_meez'),
45 '#description' => t('The profile field where users store their meez name.'),
46 );
47
48 $form["general"]["meez_avatar_types"] = array('#type' => 'textfield',
49 '#title' => t('Meez avatar types'), '#size' => 50, '#maxlength' => 50,
50 '#default_value' => variable_get('meez_avatar_types', 'head_sm,head_lg,body_sm,body_lg,anim'),
51 '#description' => t('A comma separated list of the types of avatars that you would like to have imported. Do not separate with spaces. The complete set would be head_sm,head_lg,body_sm,body_lg,anim.'),
52 );
53 $form["general"]["meez_avatar_user_page"] = array('#type' => 'textfield',
54 '#title' => t('Meez avatar to show on the user page'), '#size' => 50, '#maxlength' => 50,
55 '#default_value' => variable_get('meez_avatar_user_page', 'body_sm'),
56 '#description' => t('The avatar to show on the user profile page (e.g. user/1). Leave blank to disable this feature.'),
57 );
58
59
60
61 }
62 return system_settings_form($form);
63 }
64
65 /**
66 * Implementation of hook_user().
67 */
68 function meez_user($op, &$edit, &$account, $category = NULL) {
69
70 // Load avatars from MEEZ in case there was a change.
71 switch ($op) {
72 case 'register':
73 case 'update':
74 case 'insert':
75 // Get the location of the meez in the profile.
76 $meez_profile_field = variable_get('meez_profile_field', 'profile_meez');
77 $avatars = array();
78 // Maybe it's in the edit
79 if (isset($edit[$meez_profile_field])) {
80 $avatars = meez_get_avatars($edit[$meez_profile_field]);
81 $edit = array_merge($edit, array('avatars' => $avatars));
82 }
83 break;
84 case 'view':
85 $user_page_type = variable_get('meez_avatar_user_page', 'body_sm');
86 if (!empty($user_page_type)) {
87 if (!empty($account->avatars[$user_page_type]->src)) {
88 $picture = $account->avatars[$user_page_type]->src;
89 }
90 else if (variable_get('user_picture_default', '')) {
91 $picture = variable_get('user_picture_default', '');
92 }
93
94 if (isset($picture)) {
95 $alt = t("@user's profile", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
96 $picture = theme('image', trim($picture), $alt, $alt, '', FALSE);
97 if (!empty($account->uid) && user_access('access user profiles')) {
98 $picture = l($picture, "user/$account->uid", array('title' => t("View @user's profile.", array('@user' => $account->name)), 'html' => TRUE));
99 }
100
101 $account->content['meez_avatar'] = array(
102 '#type' => 'item',
103 '#title' => 'Meez avatar',
104 '#value' => $picture,
105 '#attributes' => array('class' => 'picture'),
106 );
107
108 }
109 else {
110 return;
111 }
112 }
113 break;
114 }
115 }
116
117 /**
118 * Iterates through a user defined list of avatars to grab
119 * and then calls the function to grab them.
120 */
121 function meez_get_avatars($av_username="") {
122 $avatars = array();
123 $avatar_types = explode(',', variable_get('meez_avatar_types', 'head_sm,head_lg,body_sm,body_lg,anim'));
124 if (!empty($av_username)) {
125 foreach ($avatar_types as $type) {
126 $avatars[trim($type)] = meez_call_meez_api($av_username, $type);
127 }
128 }
129 return ($avatars);
130 }
131
132
133 /**
134 * Connect with http://www.meez.com and get a user's meez avatar based on his/her meez username
135 */
136 function meez_call_meez_api($username, $type) {
137
138 $meez_api = 'http://partner.meez.com/avatar-ws/partner/getMeezImageURL.jsp';
139
140 $avatar_types = array();
141 $avatar_types = meez_get_types();
142
143 $meez_api .= "?username=". $username .
144 "&viewname=". $avatar_types[$type]->viewname .
145 "&imageformat=". $avatar_types[$type]->imageformat .
146 "&width=". $avatar_types[$type]->width .
147 "&height=". $avatar_types[$type]->height;
148 $result = drupal_http_request($meez_api);
149
150 switch ($result->code) {
151 case 304:
152 case 301:
153 case 200:
154 case 302:
155 case 307:
156 $meez = $avatar_types[$type];
157 $meez->src = strip_tags($result->data);
158 $meez->alt = "avatar";
159
160 break;
161 default:
162 watchdog('meez', 'The meez import seems to be broken, due to "%error".', array('%error' => theme('placeholder', $result->code .' '. $result->error)), WATCHDOG_WARNING);
163 drupal_set_message(t('The meez import seems to be broken, because of error "%error".', array('%error' => theme('placeholder', $result->code .' '. $result->error))));
164 }
165
166 return $meez;
167 }
168
169 /**
170 *
171 */
172 function meez_get_types() {
173 $avatar_types = array();
174
175 $avatar_types["head_sm"] = new stdClass();
176 $avatar_types["head_sm"]->viewname = "headshot";
177 $avatar_types["head_sm"]->imageformat = "JPG";
178 $avatar_types["head_sm"]->width = "48";
179 $avatar_types["head_sm"]->height = "48";
180
181 $avatar_types["head_lg"] = new stdClass();
182 $avatar_types["head_lg"]->viewname = "headshot";
183 $avatar_types["head_lg"]->imageformat = "JPG";
184 $avatar_types["head_lg"]->width = "100";
185 $avatar_types["head_lg"]->height = "100";
186
187 $avatar_types["body_sm"] = new stdClass();
188 $avatar_types["body_sm"]->viewname = "bodyshot";
189 $avatar_types["body_sm"]->imageformat = "JPG";
190 $avatar_types["body_sm"]->width = "175";
191 $avatar_types["body_sm"]->height = "260";
192
193 $avatar_types["body_lg"] = new stdClass();
194 $avatar_types["body_lg"]->viewname = "bodyshot";
195 $avatar_types["body_lg"]->imageformat = "JPG";
196 $avatar_types["body_lg"]->width = "300";
197 $avatar_types["body_lg"]->height = "400";
198
199 $avatar_types["anim"] = new stdClass();
200 $avatar_types["anim"]->viewname = "bodyshot";
201 $avatar_types["anim"]->imageformat = "AGIF";
202 $avatar_types["anim"]->width = "300";
203 $avatar_types["anim"]->height = "400";
204
205 return $avatar_types;
206 }

  ViewVC Help
Powered by ViewVC 1.1.2