You are here

function _photos_filter_process in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos.module \_photos_filter_process()
  2. 6.2 photos.module \_photos_filter_process()
  3. 7.3 photos.module \_photos_filter_process()
  4. 6.0.x photos.module \_photos_filter_process()

Expands on photos filter process.

1 string reference to '_photos_filter_process'
PhotosFilter::process in src/Plugin/Filter/PhotosFilter.php
Performs the filter processing.

File

./photos.module, line 1450
Implementation of photos.module.

Code

function _photos_filter_process($mat) {
  $value = '';
  if ($mat[1] == 'image' || $mat[1] == 'album') {
    $align = [
      'left' => 'photos_filter_left',
      'right' => 'photos_filter_right',
      'center' => 'photos_filter_center',
    ];
    $array = explode('|', $mat[2]);
    if (is_array($array)) {
      foreach ($array as $setting) {
        $t = explode('=', $setting);
        $set[$t[0]] = $t[1];
      }
    }
    $sizes = PhotosImage::sizeInfo();
    $style_name = '';
    if (isset($set['label'])) {
      $styles = [];

      // Check photos style label.
      foreach ($sizes['size'] as $size) {
        $styles[$size['name']] = $size['style'];
      }
      if (isset($styles[$set['label']])) {
        $style_name = $styles[$set['label']];
      }
      else {
        $styles = [];

        // Fall back on style id.
        foreach ($sizes['size'] as $size) {
          $styles[$size['style']] = $size['name'];
        }
        if (isset($styles[$set['label']])) {
          $style_name = $styles[$set['label']];
        }
      }
    }
    $set['link'] = 1;
    if ($set['id']) {
      if (preg_match('/[^\\d,]/i', $set['id'])) {
        return;
      }
      elseif (!strstr($set['id'], ',')) {
        if ($mat[1] == 'image') {
          $set['style_name'] = $style_name;
          $photos_image = new PhotosImage($set['id']);
          $image_view = $photos_image
            ->view();
          $value = \Drupal::service('renderer')
            ->render($image_view);
        }
        else {
          $db = \Drupal::database();
          $album = $db
            ->select('photos_album', 'p')
            ->fields('p', [
            'pid',
            'fid',
          ])
            ->condition('p.pid', $set['id'])
            ->execute()
            ->fetchObject();
          if (!empty($album->pid)) {
            if (isset($set['limit']) && intval($set['limit']) == $set['limit']) {
              $limit = $set['limit'] > 10 ? 10 : $set['limit'];
              $db = \Drupal::database();
              $query = $db
                ->select('file_managed', 'f');
              $query
                ->join('photos_image', 'p', 'p.fid = f.fid');
              $query
                ->fields('f', [
                'fid',
                'uri',
                'filename',
              ])
                ->condition('p.pid', $album->pid)
                ->orderBy('f.fid', 'DESC')
                ->range(0, $limit);
              $result = $query
                ->execute();
              foreach ($result as $image) {
                $set['style_name'] = $style_name;
                $photos_image = new PhotosImage($image->fid);
                $image_view = $photos_image
                  ->view();
                $value .= \Drupal::service('renderer')
                  ->render($image_view);
              }
            }
            elseif ($album->fid) {
              $set['link'] = 0;
              $set['href'] = 'photos/album/' . $album->pid;
              $set['style_name'] = $style_name;
              $photos_image = new PhotosImage($album->fid);
              $image_view = $photos_image
                ->view();
              $value = \Drupal::service('renderer')
                ->render($image_view);
            }
            else {
              $set['link'] = 0;
              $set['href'] = 'photos/album/' . $album->pid;
              $db = \Drupal::database();
              $query = $db
                ->select('file_managed', 'f');
              $query
                ->join('photos_image', 'p', 'p.fid = f.fid');
              $query
                ->fields('f', [
                'fid',
                'uri',
                'filename',
              ])
                ->condition('p.pid', $album->pid)
                ->orderBy('f.fid', 'DESC');
              $image = $query
                ->execute()
                ->fetchObject();
              $set['style_name'] = $style_name;
              $photos_image = new PhotosImage($image->fid);
              $image_view = $photos_image
                ->view();
              $value = \Drupal::service('renderer')
                ->render($image_view);
            }
          }
        }
      }
      elseif ($mat[1] == 'image') {
        $in_set_ids = explode(',', $set['id']);
        $db = \Drupal::database();
        $result = $db
          ->select('file_managed', 'f')
          ->fields('f', [
          'fid',
          'uri',
          'filename',
        ])
          ->condition('f.fid', $in_set_ids, 'IN')
          ->execute();
        foreach ($result as $image) {
          $set['style_name'] = $style_name;
          $photos_image = new PhotosImage($image->fid);
          $image_view = $photos_image
            ->view();
          $value .= \Drupal::service('renderer')
            ->render($image_view);
        }
      }
      if ($value) {
        $set_align = isset($set['align']) ? $set['align'] : '';
        $output = isset($align[$set_align]) ? '<div class="' . $align[$set_align] . '">' : '';
        $output .= $value;
        $output .= isset($align[$set_align]) ? '</div>' : '';
        return $output;
      }
    }
  }
}