You are here

function _photos_filter_process in Album Photos 7.3

Same name and namespace in other branches
  1. 8.5 photos.module \_photos_filter_process()
  2. 8.4 photos.module \_photos_filter_process()
  3. 6.2 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'
photos_filter_process in ./photos.module
Photos filter process.

File

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

Code

function _photos_filter_process($mat) {
  $value = '';
  if ($mat[1] == 'image' || $mat[1] == 'album') {
    $align = array(
      '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 = photos_upload_info(0);
    $style_name = '';
    if (isset($set['label'])) {
      $styles = array();

      // 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 = array();

        // 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;
          $value = photos_get_info($set['id'], 0, $set);
        }
        else {
          $album = db_select('photos_album', 'p')
            ->fields('p', array(
            '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'];
              $query = db_select('file_managed', 'f');
              $query
                ->join('photos_image', 'p', 'p.fid = f.fid');
              $query
                ->fields('f', array(
                '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;
                $value .= photos_get_info(0, $image, $set);
              }
            }
            elseif ($album->fid) {
              $set['link'] = 0;
              $set['href'] = 'photos/album/' . $album->pid;
              $set['style_name'] = $style_name;
              $value = photos_get_info($album->fid, 0, $set);
            }
            else {
              $set['link'] = 0;
              $set['href'] = 'photos/album/' . $album->pid;
              $query = db_select('file_managed', 'f');
              $query
                ->join('photos_image', 'p', 'p.fid = f.fid');
              $query
                ->fields('f', array(
                'fid',
                'uri',
                'filename',
              ))
                ->condition('p.pid', $album->pid)
                ->orderBy('f.fid', 'DESC');
              $image = $query
                ->execute()
                ->fetchObject();
              $set['style_name'] = $style_name;
              $value = photos_get_info(0, $image, $set);
            }
          }
        }
      }
      elseif ($mat[1] == 'image') {
        $in_set_ids = explode(',', $set['id']);
        $result = db_select('file_managed', 'f')
          ->fields('f', array(
          'fid',
          'uri',
          'filename',
        ))
          ->condition('f.fid', $in_set_ids, 'IN')
          ->execute();
        foreach ($result as $image) {
          $set['style_name'] = $style_name;
          $value .= photos_get_info(0, $image, $set);
        }
      }
      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;
      }
    }
  }
}