You are here

function theme_flag_lists_list in Flag Lists 7

Same name and namespace in other branches
  1. 6 flag_lists.module \theme_flag_lists_list()
  2. 7.3 flag_lists.module \theme_flag_lists_list()
1 theme call to theme_flag_lists_list()
flag_lists_block_view in ./flag_lists.module
Implements hook_block_view().

File

./flag_lists.module, line 1003
The Flag Lists module.

Code

function theme_flag_lists_list($variables) {
  $node = $variables['node'];
  $create = $variables['create'];
  $ops = $variables['ops'];
  $use_flags = $variables['use_flags'];
  $items = array();

  // Make sure we have a node.
  if (is_object($node) && user_access('create flag lists')) {
    $content_type = $node->type;
    $content_id = $node->nid;
  }
  elseif (arg(0) == 'node' && is_numeric(arg(1)) && user_access('create flag lists')) {
    $content_id = arg(1);
    $query = db_select('node')
      ->condition('nid', $content_id);
    $query
      ->addField('node', 'type');
    $content_type = $query
      ->execute()
      ->fetchField();
  }
  else {
    return;
  }

  // Do we have a list template for this node type, or are we s
  if (!flag_lists_template_exists($content_type) && !$use_flags) {
    return;
  }
  global $user;
  if ($flags = flag_lists_get_user_flags($content_type, $user, $use_flags)) {

    // Build the list of lists for this node.
    foreach ($flags as $flag) {
      if ($flag->module == 'flag_lists') {
        $action = _flag_lists_is_flagged($flag, $content_id, $user->uid, 0) ? 'unflag' : 'flag';
      }
      else {
        $action = $flag
          ->is_flagged($content_id) ? 'unflag' : 'flag';
      }

      // Do we need the ops?
      if ($ops && $flag->module == 'flag_lists') {
        $ops_links = theme('flag_lists_ops', array(
          'flag' => $flag,
        ));
        $link = $flag
          ->theme($action, $content_id) . $ops_links;
      }
      else {
        $link = $flag
          ->theme($action, $content_id);
      }

      // If it's a list, fix the link.
      if ($flag->module == 'flag_lists') {
        flag_lists_fix_link($link, $action);
      }
      $items[] = $link;
    }
  }
  if ($create && flag_lists_template_exists($content_type)) {
    $items[] = l(t('Make a new @name', array(
      '@name' => variable_get('flag_lists_name', t('list')),
    )), 'flag-lists/add/' . $content_type, array(
      'query' => drupal_get_destination(),
    ));
  }

  // Return if nothing to display.
  if (empty($items) || !count($items)) {
    return;
  }
  drupal_add_css(drupal_get_path('module', 'flag_lists') . '/theme/flag_lists.css');
  return theme('item_list', array(
    'items' => $items,
    'type' => 'ul',
    'attributes' => array(
      'class' => 'flag-lists-links',
    ),
  ));
}