Location: PHPKode > projects > Teampopor > teampopor-0.5/teampopor/modules/message/message.pages.inc
<?php

// page callback: network/%network/file/%file/download
function network_file_download($network, $file) {
  if (file_exists($file->path)) {
    $headers = array('Content-type: '. $file->mime);
    file_transfer($file->path, $headers);
  }
  else {
    return drupal_not_found();
  }
}

/**
 * page callback: message/%message/js/%
 *
 * @param $message
 *   The message object
 *
 * @param $action
 *   The action to be perform.
 *
 * @return
 *   The JSON object.
 */
function message_js($message, $action) {
  switch ($action) {
    case 'like':
      like_save(NULL, array(
        'mid' => $message->mid,
      ));
      return json('SUCCESS');
    case 'unlike':
      global $user;
      if ($like = like_load(array('mid' => $message->mid, 'uid' => $user->uid))) {
        like_delete($like);
        return json('SUCCESS');
      }
      return json('FAIL');
    case 'add-tag':
      $tag_name = trim(arg(4));
      if (!($tag = tag_load(array('nid' => $message->nid, 'name' => $tag_name)))) {
        $tag = tag_save(NULL, array(
          'nid' => $message->nid,
          'name' => $tag_name,
        ));
      }
      if (!message_tag_load(array('mid' => $message->mid, 'tid' => $tag->tid))) {
        message_tag_save(NULL, array(
          'mid' => $message->mid,
          'tid' => $tag->tid,
        ));
      }
      return json($tag);
  }
}

/**
 * page callback: message/%message/tag/%tag/js/%
 */
function message_tag_js($message, $tag, $action) {
  switch ($action) {
    case 'delete':
      if ($message_tag = message_tag_load(array('mid' => $message->mid, 'tid' => $tag->tid))) {
        message_tag_delete($message_tag);
      }
      return json('SUCCESS');
  }
}

/**
 * page callback: message/share/js
 */
function message_attach_file_js() {
  $cached_form_state = array();
  $files = array();

  // Load the form from the Form API cache.
  if (!($cached_form = form_get_cache($_POST['form_build_id'], $cached_form_state)) || !isset($cached_form['attach_file'])) {
    form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.'));
    $output = theme('status_messages');
    print to_js(array('status' => TRUE, 'data' => $output));
    exit();
  }

  $form_state = array('values' => $_POST);

  // Handle new attaches
  attach_file_form_submit($cached_form, $form_state);

  if (!empty($form_state['values']['attach_files'])) {
    foreach ($form_state['values']['attach_files'] as $fid => $file) {
      if (isset($cached_form['#files'][$fid])) {
        $files[$fid] = $cached_form['#files'][$fid];
      }
    }
  }

  $form = _attach_file_form($files);

  form_set_cache($_POST['form_build_id'], $cached_form, $cached_form_state);

  // Render the form for output.
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
    '#tree' => FALSE,
    '#parents' => array(),
  );
  $form_state = array('submitted' => FALSE);
  $form = form_builder('message_attach_file_js', $form, $form_state);
  $output = theme('status_messages') . render($form);

  // We send the updated file attachments form.
  // Don't call json(). ahah.js uses an iframe and
  // the header output by json() causes problems in some browsers.
  print to_js(array('status' => TRUE, 'data' => $output));
  exit;
}
Return current item: Teampopor