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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Drupal imagecache function
Pages: [1]

Author Topic: Drupal imagecache function  (Read 340 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Drupal imagecache function
May 12, 2014, 06:23:09 am
I just updated someone else's code (for 4.4.6) which formats a civicrm image as a drupal imagecache image - thought I'd post the code here

Code: [Select]
    if(!empty($contactl['image_URL'])) {
      $drupalArr['photo'] = theme(
        'image_style', array(
          'style_name' => 'profile_style1',
          'path' => myext_get_imagecache_url($contactl['image_URL'],
          'attributes' => array('class' => 'picture', 'width' => '140', 'height' => '167'))),
    }


**
 * Get url appropriate for drupal theme function - e.g.  public://civicrm/custom/DSC_9307_2ec5264892c42c8839f93aaa1bc7b2f4.jpg
 * @param unknown $civiURL
 * @return string
 */
function myext_get_imagecache_url($civiURL) {

  $default_image = 'public://no-pic-en.jpg';
  if(empty($civiURL)) {
    return $default_image;
  }
  $imagesDirectory = CRM_Core_Config::singleton()->customFileUploadDir;
  $file_path = '/sites/default/files/';
  $image_parts = explode('=', $civiURL);
  $pos = strpos($imagesDirectory, $file_path);
  // Don't know where the heck this image is
  if ($pos === false) {
    // TODO: localization
    $url = $default_image;
  }
  // Found it
  else {
    $url = 'public://' . substr($imagesDirectory, $pos + strlen($file_path)) . array_pop($image_parts);
    if(!file_exists($url)) {
      $url = $default_image;
    }
  }
  return $url;
}
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Drupal imagecache function

This forum was archived on 2017-11-26.