You are here

function uc_product_store_status in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_product/uc_product.module \uc_product_store_status()

Implements hook_store_status().

Displays the status of the product image handlers.

See also

uc_product_image_defaults()

File

uc_product/uc_product.module, line 1089
The product module for Ubercart.

Code

function uc_product_store_status() {
  if (!module_exists('imagefield') || !module_exists('imagecache')) {
    $status = 'warning';
    $description = t('To automatically configure core image support, <a href="!url">enable</a> the <a href="http://drupal.org/project/cck">Content</a>, <a href="http://drupal.org/project/imagefield">CCK Image field</a>, and <a href="http://drupal.org/project/imagecache">Imagecache</a> modules.', array(
      '!url' => url('admin/build/modules'),
    ));
  }
  else {
    module_load_include('inc', 'content', 'includes/content.crud');

    // Check for filefields on products.
    if ($field = variable_get('uc_image_product', '')) {
      $instances = content_field_instance_read(array(
        'field_name' => $field,
        'type_name' => 'product',
      ));
      $field_check = (bool) count($instances);
    }
    else {
      $field_check = FALSE;
    }
    $presets = array(
      'product',
      'product_full',
      'product_list',
      'uc_thumbnail',
    );
    if (module_exists('uc_catalog')) {
      $presets[] = 'uc_category';
    }
    if (module_exists('uc_cart')) {
      $presets[] = 'cart';
    }
    sort($presets);
    $preset_check = 1;
    $action_check = 1;
    foreach ($presets as $preset_name) {
      $preset = imagecache_preset_by_name($preset_name);
      if (empty($preset)) {
        $preset_check = 0;
        $action_check = 0;
        break;
      }
      else {
        if (empty($preset['actions']) && $preset_name != 'product_full') {
          $action_check = 0;
          break;
        }
      }
    }
    if ($field_check && $preset_check && $action_check) {
      $status = 'ok';
      $description = t('Product image support has been automatically configured by Ubercart.');
    }
    else {
      $status = 'warning';
      $description = t('<a href="!url">Click here</a> to automatically configure the following items for core image support:', array(
        '!url' => url('admin/store/settings/products/defaults'),
      ));
      if (!$field_check) {
        $items[] = t('The Image file field has not been created for products.');
      }
      if (!$preset_check) {
        $items[] = t('Some or all of the expected Imagecache presets ("!presets") have not been created. Ubercart will not display images in certain places.', array(
          '!presets' => implode('", "', $presets),
        ));
      }
      if (!$action_check) {
        $items[] = t('Some Imagecache presets do not contain actions to perform on images. Images may be displayed in their original formats.');
      }
      $description .= theme('item_list', $items) . t('(This action is not required and should not be taken if you do not need images or have implemented your own image support.)');
    }
  }
  return array(
    array(
      'status' => $status,
      'title' => t('Images'),
      'desc' => $description,
    ),
  );
}