You are here

function photos_nodeapi in Album Photos 6.2

File

./photos.module, line 364

Code

function photos_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
    case 'load':
      if ($node->type == 'photos') {
        $a = db_fetch_object(db_query('SELECT * FROM {x_album} WHERE pid = %d', $node->nid));
        if ($a->pid) {
          $info['album'] = unserialize($a->data);
          $info['album']['pid'] = $a->pid;
          $info['album']['count'] = $a->count;
          if ($a->fid && ($image = db_fetch_array(db_query('SELECT * FROM {files} WHERE fid = %d', $a->fid)))) {
            $image = photos_get_info(0, $image);
            $info['album']['cover']['fid'] = $a->fid;
            $thumb = variable_get('photos_title_0', false);
            $info['album']['cover']['url'] = url($image['thumb'][$thumb]);
            $info['album']['cover']['view'] = theme('photos_imagehtml', $image['thumb'][$thumb], array(
              'href' => 'photos/album/' . $node->nid,
              'filename' => check_plain($node->title),
            ));
          }
          else {
            $image = db_fetch_array(db_query_range('SELECT f.* FROM {files} f INNER JOIN {x_image} p ON f.fid = p.fid WHERE p.pid = %d ORDER BY f.fid DESC', $node->nid, 0, 1));
            if ($image['fid']) {
              $image = photos_get_info(0, $image);
              $thumb = variable_get('photos_title_0', false);
              $info['album']['cover']['url'] = _photos_l($image['thumb'][$thumb]);
              $info['album']['cover']['view'] = theme('photos_imagehtml', $image['thumb'][$thumb], array(
                'href' => 'photos/album/' . $node->nid,
                'filename' => check_plain($node->title),
              ));
            }
          }
        }
      }
      else {
        if (variable_get('photos_node_' . $node->type, 0)) {
          $photo = db_fetch_object(db_query("SELECT cid, value FROM {x_count} WHERE cid = %d AND type = '%s'", $node->nid, 'node_node'));
          if ($photo->cid) {
            $info['subalbum']['count'] = $photo->value;
          }
        }
      }
      return $info;
      break;
    case 'view':
      if ($node->album['pid']) {
        if ($teaser) {
          $album = _photos_node_view($node, $node->album['teaser_display'], 'teaser');
        }
        else {
          $album = _photos_node_view($node, $node->album['page_display'], 'page');
        }
        if ($album) {
          $node->content['album']['#value'] = '<div class="clear-block">' . $album . '</div>';
        }
      }
      break;
    case 'validate':
      if ($node->type == 'photos') {
        $t = photos_user_count();
        $t['rest'] ? form_set_error('title', t('You cannot create more albums.')) : NULL;
        if (preg_match('/[^0-9x]/i', $node->album['slide'])) {
          form_set_error('album][slide', t('Slide size is not correct.'));
        }
        if (preg_match('/[^0-9x]/i', $node->album['teaser_slide'])) {
          form_set_error('album][teaser_slide', t('Slide size is not correct.'));
        }
        if (preg_match('/[^0-9x]/i', $node->album['page_slide'])) {
          form_set_error('album][page_slide', t('Slide size is not correct.'));
        }
      }
      break;
    case 'insert':
    case 'update':
      if ($node->type == 'photos') {
        if (!$node->album['pid']) {
          db_query("INSERT INTO {x_album} (pid, data, fid, count) VALUES (%d, '%s', 0, 0)", $node->nid, serialize($node->album));
        }
        else {
          db_query("UPDATE {x_album} SET data = '%s' WHERE pid = '%s'", serialize($node->album), $node->nid);
        }
        photos_set_count('user_album', $node->uid);
      }
      break;
    case 'delete':
      if ($node->type == 'photos') {
        if ($node->album['count'] || !variable_get('photos_user_count_cron', 0)) {
          $result = db_query('SELECT f.fid, f.filepath FROM {files} f INNER JOIN {x_image} p ON f.fid = p.fid WHERE p.pid = %d', $node->nid);
          while ($file = db_fetch_object($result)) {
            $msg[] = photos_file_del($file->fid, $file->filepath);

            //删除相册下所有图片
          }
          if ($msg[0]) {
            photos_set_count('user_image', $node->uid);
            drupal_set_message(t('%count images are deleted.', array(
              '%count' => COUNT($msg),
            )));
          }
        }
        photos_set_count('user_album', $node->uid);
        db_query('DELETE FROM {x_album} WHERE pid = %d', $node->nid);
      }
      if (variable_get('photos_node_' . $node->type, 0)) {
        db_query('DELETE FROM {x_node} WHERE nid = %d', $node->nid);

        //移除节点下所有图片,图片仍存在于相册中
        db_query("DELETE FROM {x_count} WHERE cid = %d AND type = '%s'", $node->nid, 'node_node');

        //移除统计记录
      }
  }
}