You are here

function theme_heartbeat_filters in Heartbeat 6.4

Theme function for filters on activity messages.

1 theme call to theme_heartbeat_filters()
theme_heartbeat_list in ./heartbeat.module
Theme function for a list of heartbeat activity messages.

File

./heartbeat.module, line 782

Code

function theme_heartbeat_filters(HeartbeatStream $stream) {
  $output = '';
  if (!empty($stream->filters)) {
    $active_filters = $new_filter = array();
    $path = $_GET['q'];
    $output = '<ul class="heartbeat-filters">';
    $cumul = $stream->filters_cumul;
    $all = variable_get('heartbeat_filters', array());
    if (isset($_GET['filters'])) {
      $active_filters = drupal_map_assoc(explode(',', $_GET['filters']));
    }
    foreach ($stream->filters as $filter => $data) {

      // Check if this filter exists
      if (!isset($all[$filter])) {
        continue;
      }

      // Check the access (callback) for this filter
      $access = TRUE;
      if (isset($all[$filter]['access'])) {
        $access = !is_numeric($all[$filter]['access']) ? call_user_func($all[$filter]['access']) : (bool) $all[$filter]['access'];
      }
      if (!$access) {
        continue;
      }
      $new_filter = $active_filters;
      if (isset($active_filters[$filter])) {
        $class = 'heartbeat-filter-unset';
        unset($new_filter[$filter]);
      }
      elseif ($filter == 'all' && empty($active_filters)) {
        $class = 'heartbeat-filter-unset';
      }
      else {
        $class = 'heartbeat-filter-set';
        $new_filter[$filter] = $filter;
      }
      $output .= '<li class="heartbeat-filter ' . $class . '">';
      $fragment = 'heartbeat-stream-' . $stream->name;
      if ($filter == 'all' || count($new_filter) == 0) {
        $output .= l(t($all[$filter]['name']), $path, array(
          'fragment' => $fragment,
        ));
      }
      else {
        if ($cumul) {
          $query = array(
            'absolute' => TRUE,
            'fragment' => $fragment,
            'query' => 'filters=' . implode(',', $new_filter),
          );
        }
        else {
          $query = array(
            'absolute' => TRUE,
            'fragment' => $fragment,
            'query' => 'filters=' . $filter,
          );
        }
        $output .= l(t($all[$filter]['name']), $path, $query);
      }
      $output .= '</li>';
    }
    $output .= '</ul>';
  }
  return $output;
}