CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Custom data image, Drupal Views, Thumbnails?
Pages: 1 ... 5 6 [7]

Author Topic: Custom data image, Drupal Views, Thumbnails?  (Read 31188 times)

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
December 04, 2010, 08:26:12 pm
Read the error message carefully.  It gives you the information you need to figure out where the problem is happening -- and you'll learn something about PHP. 

The solution I don't know off the top of my head.  It sounds like either the CiviCRM API and file structure changed in 3.3, or something about your include path changed.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
December 04, 2010, 09:02:45 pm
I did read the error message carefully. That's how I found the line of code that was causing the problem.

I'll take another look at it tomorrow; hopefully, something will click after I've had a night's sleep.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
December 04, 2010, 09:57:32 pm
Bah, you were right. That was stupid simple. My bad. The file path for api/File.php changed to api/v2/File.php ... but now the site is throwing another error:

Fatal error: Call to undefined function crm_get_file() in ~/sites/all/themes/blueprint/[sub-theme]/template.php on line 160

template.php line 160 doesn't offer much in the way of easy clues:

Code: [Select]
$files = crm_get_file(array('id'=>$id));
Again, I'll look it over more tomorrow.

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: Custom data image, Drupal Views, Thumbnails?
December 05, 2010, 08:52:07 pm
you might want to try to use civicrm_file_get( $params ) instead of crm_get_file( );

here is the related document for file api's http://wiki.civicrm.org/confluence/display/CRMDOC33/File+APIs

hope this help

kiran
You Are Designed To Choose... Defined By Choice.

fm

  • I post occasionally
  • **
  • Posts: 80
  • Karma: 1
Re: Custom data image, Drupal Views, Thumbnails?
December 06, 2010, 06:50:17 am
Quote from: Kiran Jagtap on December 05, 2010, 08:52:07 pm
you might want to try to use civicrm_file_get( $params ) instead of crm_get_file( );

here is the related document for file api's http://wiki.civicrm.org/confluence/display/CRMDOC33/File+APIs

hope this help

kiran

Kiran, you were exactly correct. The function has been changed in v2 API, which was confusing/frustrating because even the 'File APIs' documentation to which you linked still displays the old style. I had seen that documentation previously and accepted it as gospel. Your post caused me to go check again how the function was defined in api/v2/File.php, and sure enough the recommended version of the function from your post matched how the function was defined in api/v2/File.php.

While searching CiviCRM.org for your version, I found this table summarizing the v2 changes:
http://wiki.civicrm.org/confluence/display/CRMDOC32/Deprecated+v1+API's

A big thank you to you, kiran.

For the convenience of others reading this thread, the table summary linked above includes:

crm_get_file    Deprecated V1 API
civicrm_file_get    Equivalent V2 API
civicrm_file_get    To be standardised V3 API
« Last Edit: December 06, 2010, 07:01:48 am by fm »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Custom data image, Drupal Views, Thumbnails?
December 06, 2010, 07:06:46 am
Hi,

Could you update the wiki when you find something that isn't up to date ?

Also, you might use the api.civicrm.org We are trying to add more information and specifically the details about what params are possible.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

bevanr01

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 3.2
  • CMS version: Drupal
  • MySQL version: 5.0.91
  • PHP version: 5
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 08:53:46 am
I can't seem to get this to work and I followed along the entire way. I have this in my views template file.
Quote
<?php $image_uri = url(get_civicrm_image($fields['image-2']->content)); ?>
<img src="<?php echo $image_uri; ?>" />
And this is the function in template
Quote
function get_civicrm_image($id, $dimensions=array(200,200)) {
   civicrm_initialize();
   require_once('api/v2/File.php');
   
   // get the file details
       $files = civicrm_file_get(array('id'=>$id));
       $file = array_shift($files);
   $filename = $file['uri'];
   
   $root = $_SERVER['DOCUMENT_ROOT'];
   $file_ext = strrchr($filename, '.');
   $file_base = substr($filename, 0, 0 - strlen($file_ext));
   $old_path = $root . '/' . file_directory_path() . '/civicrm/custom/' . $filename;
   $new_file = file_directory_path() . '/civicrm/custom/' . $file_base . '_' . $dimensions[0] . 'x' . $dimensions[1] . $file_ext;
   if(!file_exists($root . '/' . $new_file)) {
       image_scale_and_crop($old_path, $root . '/' . $new_file, $dimensions[0], $dimensions[1]);
   }
   return $new_file;
}
I am getting the error "warning: Division by zero in.." It outputs the field label along with the ID. "image: 2"
Any suggestions?

BTW not sure why I couldn't use the code tags.....

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 09:18:13 am
bevan, could you please post the full text of the error message?  That tends to be useful when tracking down a bug of this sort.  Thanks.

bevanr01

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 3.2
  • CMS version: Drupal
  • MySQL version: 5.0.91
  • PHP version: 5
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 09:22:55 am
Sorry. Kept getting the "Sorry you cannot post external links." error so I changed my post around so many times.

The error is:

Quote
warning: Division by zero in /home/politi33/public_html/afceasiliconbayou.org/includes/image.inc on line 160.

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 09:38:45 am
I suspect that the code is generating the wrong path for the existing file and therefore passing an invalid path to image_scale_and_crop.  You'll have to use print statements or some other method of debugging to help you adjust the code in get_civicrm_image() to return the correct path to the file.

bevanr01

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 3.2
  • CMS version: Drupal
  • MySQL version: 5.0.91
  • PHP version: 5
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 10:26:12 am
Ok so now I'm able to print the image url and I am getting an image placeholder where the image should be. I also confirmed that the image does exist in the correct directory and it has been resided according to the function.

I am still getting the error as well.

bevanr01

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 3.2
  • CMS version: Drupal
  • MySQL version: 5.0.91
  • PHP version: 5
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 10:34:54 am
I noticed I am getting "/?q=" before the image url when it shouldn't be there, because I can't browse to the image unless it is not there. For example example.com/sites/default/files/civicrm/custom/image.jpg vice example.com/?q=/sites/default/files/civicrm/custom/image.jpg How do I get rid of that?

lentilsoup

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 6
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 10:43:42 am
That almost certainly has something to do with your URL rewriting settings (aka mod_rewrite).

bevanr01

  • I’m new here
  • *
  • Posts: 5
  • Karma: 0
  • CiviCRM version: 3.2
  • CMS version: Drupal
  • MySQL version: 5.0.91
  • PHP version: 5
Re: Custom data image, Drupal Views, Thumbnails?
March 31, 2011, 11:02:30 am
You were exactly right.

For some odd reason my .htaccess file wasn't loaded during installation/transfer to server so cleanurls wasn't enabled. I usually enable cleanurls during installation which is why I didn't even think of it. I appreciate your help!

Pages: 1 ... 5 6 [7]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Custom data image, Drupal Views, Thumbnails?

This forum was archived on 2017-11-26.