You are here

function template_preprocess_amazon_component_reviews in Amazon Product Advertisement API 7.2

File

amazon_component/amazon_component.preprocess.inc, line 45

Code

function template_preprocess_amazon_component_reviews(&$variables) {

  // Fucntion Variables
  $db = array();
  $reviews = array();

  // Explode :: Convert current page alias into array
  $currentAlias = explode('/', drupal_get_path_alias());

  // IF :: the block is being rendered on Amazon Product Node type or Amazon Store Module path proceed.
  if ($currentAlias[0] == 'product' || $currentAlias[0] == variable_get('amazon_store_path')) {
    $reviews[$currentAlias[1]] = _amazon_component_fetch_reviews($currentAlias[1]);

    // Foreach :: Review
    foreach ($reviews[$currentAlias[1]] as $key => $review) {

      // Content Variables

      /* ----------------------------------------------------------------- */
      $variables['title'] = isset($review->title) ? $review->title : '';
      $db['body'] = !empty($review->body) ? $review->body['und'] : '';
      $db['field_tagline'] = !empty($review->field_tagline) ? $review->field_tagline['und'] : '';
      $db['field_introduction'] = !empty($review->field_introduction) ? $review->field_introduction['und'] : '';
      $db['field_tl_dr'] = !empty($review->field_tl_dr) ? $review->field_tl_dr['und'] : '';
      $db['field_review_pros'] = !empty($review->field_review_pros) ? $review->field_review_pros['und'] : '';
      $db['field_review_cons'] = !empty($review->field_review_cons) ? $review->field_review_cons['und'] : '';

      // Foreach
      foreach ($db as $key_field => $value) {
        if (!empty($value)) {
          $field = field_get_items('node', $review, $key_field);
          foreach ($field as $key => $value) {
            $field_rendered = field_view_value('node', $review, $key_field, $field[$key]);

            // Variables :: Check to see if it's text, image, etc...
            $variables[$key_field][$key] = isset($field_rendered['#markup']) ? $field_rendered['#markup'] : $field_rendered;
          }
        }
      }

      // Image Variables

      /* ----------------------------------------------------------------- */
      $db_images = !empty($review->field_featured_image) ? $review->field_featured_image['und'] : '';
      foreach ($db_images as $key => $image) {
        $variables['images'][$key] = theme('image', array(
          'path' => $image['uri'],
          'attributes' => array(
            'height' => $image['height'],
            'width' => $image['width'],
          ),
          'getsize' => FALSE,
        ));
      }
    }
  }
}