@@ -134,18 +134,16 @@ class civicrm_handler_field_contact_image extends views_handler_field {
134134 * */
135135 function pre_render (&$ values ) {
136136 parent ::pre_render ($ values );
137- /* Break the url to the contact image into it's parts, find the point in the array
138- * that is the files directory, slice out the remaining path elements, glue them back
139- * up into a path and make a public file uri out of that. Then turn the uri into a
140- * Drupal file object and replace the result so the render function can style the image.
141- * */
137+ $ config = CRM_Core_Config::singleton ();
142138 foreach ($ values as $ key => $ row ) {
143139 $ file = array ();
140+ // This is the public url (which gets routed through civi)
144141 $ img_url = $ this ->get_value ($ row );
145- $ url_parts = explode ('/ ' , $ img_url );
146- $ files_key = array_search ('files ' , $ url_parts );
147- $ url_parts = array_slice ($ url_parts , $ files_key + 1 );
148- $ file_path = 'public:// ' . implode ('/ ' , $ url_parts );
142+ if (!$ img_url ) {
143+ continue ;
144+ }
145+ // This is the internal file path
146+ $ file_path = $ config ->customFileUploadDir . substr (strstr ($ img_url , 'photo= ' ), 6 );
149147 $ image_info = image_get_info ($ file_path );
150148 if ($ image_info ) {
151149 $ file ['width ' ] = $ image_info ['width ' ];
@@ -163,7 +161,7 @@ class civicrm_handler_field_contact_image extends views_handler_field {
163161 }
164162 else {
165163 if (!empty ($ this ->options ['picture_group ' ])) {
166- $ file ['uri ' ] = $ file_path ;
164+ $ file ['uri ' ] = $ img_url ;
167165 $ mappings = picture_mapping_load ($ this ->options ['picture_group ' ]);
168166 $ file ['breakpoints ' ] = picture_get_mapping_breakpoints ($ mappings , $ this ->options ['fallback_image_style ' ]);
169167 }
@@ -187,14 +185,14 @@ class civicrm_handler_field_contact_image extends views_handler_field {
187185 elseif (!empty ($ this ->options ['image_style ' ])) {
188186 $ file ['style_name ' ] = $ this ->options ['image_style ' ];
189187 }
190- $ file ['path ' ] = $ file_path ;
188+ $ file ['path ' ] = $ img_url ;
191189 $ file ['title ' ] = $ this ->options ['title ' ];
192190 }
193191 /* if file['uri'] was not set in the Picture module conditional, and $file['path] is not set
194192 * in the image style conditional just completed, then set the path and so we have something to theme
195193 * */
196194 if ((!isset ($ file ['uri ' ])) && (!isset ($ file ['path ' ]))) {
197- $ file ['path ' ] = $ file_path ;
195+ $ file ['path ' ] = $ img_url ;
198196 $ file ['title ' ] = $ this ->options ['title ' ];
199197 }
200198 $ values [$ key ]->{$ this ->field_alias } = $ file ;
@@ -213,7 +211,7 @@ class civicrm_handler_field_contact_image extends views_handler_field {
213211 elseif (!empty ($ file ['style_name ' ])) {
214212 return theme ('image_style ' , $ file );
215213 }
216- else {
214+ elseif ( $ file ) {
217215 return theme ('image ' , $ file );
218216 }
219217 }
0 commit comments