You are here

function photos_share in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 inc/photos.page.inc \photos_share()

Share photos.

1 string reference to 'photos_share'
photos_menu in ./photos.module
Implements hook_menu().

File

inc/photos.page.inc, line 235
Handles default page view(s) and content.

Code

function photos_share() {
  global $user;
  $output = '';
  $order = explode('|', variable_get('photos_display_imageorder', 'timestamp|desc'));
  $order = _photos_order_value_change($order[0], $order[1]);
  $column = isset($_GET['field']) ? check_plain($_GET['field']) : 0;
  $sort = isset($_GET['sort']) ? check_plain($_GET['sort']) : 0;
  $term = _photos_order_value($column, $sort, 20, $order);
  if (arg(2) != 'all') {
    $query = db_select('file_managed', 'f')
      ->extend('PagerDefault');
    $query
      ->join('photos_image', 'p', 'p.fid = f.fid');
    $query
      ->fields('f', array(
      'uid',
      'fid',
      'uri',
      'filemime',
      'filename',
    ))
      ->fields('p', array(
      'title',
    ));
    $query
      ->condition('f.uid', $user->uid);
    $query
      ->orderBy($term['order']['column'], $term['order']['sort']);
    $query
      ->limit($term['limit']);
    $result = $query
      ->execute();
    $images['menu'] = _photos_order_link('photos/share', 0, 0, 1);
  }
  else {
    $query = db_select('file_managed', 'f')
      ->extend('PagerDefault');
    $query
      ->join('photos_image', 'p', 'p.fid = f.fid');
    $query
      ->join('users', 'u', 'u.uid = f.uid');
    $query
      ->fields('f', array(
      'fid',
      'uri',
      'filemime',
      'filename',
      'timestamp',
      'filesize',
    ))
      ->fields('p', array(
      'title',
    ))
      ->fields('u', array(
      'uid',
      'name',
    ));
    $query
      ->condition('f.uid', $user->uid, '<>');
    $query
      ->orderBy($term['order']['column'], $term['order']['sort']);
    $query
      ->limit($term['limit']);
    $result = $query
      ->execute();
    $images['menu'] = _photos_order_link('photos/share/all', 0, 0, 1);
  }
  $style_name = variable_get('photos_thumb_imagesize', 'thumbnail');
  foreach ($result as $data) {
    $image = photos_get_info(0, $data);
    if (is_array($image->thumb)) {
      foreach ($image->thumb as $key => $thumb) {
        $thumbs[$thumb] = _photos_l($image->uri, $key);
      }
    }
    $username = '';
    if (isset($image->name) && isset($image->uid)) {
      $username = t('By: !name', array(
        '!name' => l($image->name, 'photos/user/' . $image->uid . '/image'),
      ));
    }
    $share[] = array(
      'link' => url('photos/image/' . $image->fid, array(
        'absolute' => TRUE,
      )),
      'fid' => $image->fid,
      'filename' => $image->filename,
      'title' => $image->title,
      'thumbs' => $thumbs,
      'username' => $username,
      'view' => theme('photos_imagehtml', array(
        'style_name' => $style_name,
        'image' => $image,
      )),
    );
  }
  $images['links'] = l(t('« Back'), 'photos') . l(t('My images'), 'photos/share') . l(t('All the shared images'), 'photos/share/all');
  $images['data'] = isset($share[0]['fid']) ? $share : '';
  $output .= theme('photos_share', array(
    'images' => $images,
    'type' => 'image',
  ));
  $output .= theme('pager');
  print $output;
}