You are here

function kml_interface in KML 6

Same name and namespace in other branches
  1. 5 kml.module \kml_interface()

Default callback

1 string reference to 'kml_interface'
kml_menu in ./kml.module
Implementation of hook_menu().

File

./kml.module, line 69
KML Module

Code

function kml_interface($a = NULL, $b = NULL, $c = NULL, $d = NULL, $e = NULL) {
  $sortmode = variable_get('kml_sortmode', 'n.created');
  $sortorder = variable_get('kml_sortorder', 'asc');
  if ($a == 'node') {
    if (is_numeric($b)) {

      /* Single node */
      if ($c == 'networklink') {
        $attributes['kml_feed'] = url('kml/node/' . $b, array(
          'absolute' => TRUE,
        ));
        kml_networklink($attributes);
      }
      else {
        $cache_name = 'kml:node:' . $b;
        $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location_instance} l ON n.vid = l.vid WHERE n.status = 1 AND n.nid = %d", $b);
        _kml_feed_check_access($nodes, $attributes, $cache_name);
      }
    }
    else {
      if ($b == 'networklink') {

        /* Network link for all location-enabled nodes */
        $attributes['kml_feed'] = url('kml/node/', array(
          'absolute' => TRUE,
        ));
        kml_networklink($attributes);
      }
      else {

        /* All location-enabled nodes */
        $cache_name = 'kml:node';
        $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location_instance} l ON n.vid = l.vid WHERE n.status = 1 ORDER BY %s %s", $sortmode, $sortorder);
        _kml_feed_check_access($nodes, $attributes, $cache_name);
      }
    }
  }
  else {
    if ($a == 'term' && is_numeric($b)) {
      if (module_exists('taxonomy')) {
        if ($term = taxonomy_get_term($b)) {
          $tag = $term->name;
          if ($c == 'networklink') {

            /* Network link for all location-enabled nodes tagged with a certain term */
            $attributes['kml_feed'] = url('kml/term/' . $b . '/', array(
              'absolute' => TRUE,
            ));
            $attributes['title'] = t('Tag: %tag', array(
              '%tag' => $tag,
            ));
            $attributes['description'] = t('Nodes tagged with %tag', array(
              '%tag' => $tag,
            ));
            kml_networklink($attributes);
          }
          else {

            /* All location-enabled nodes tagged with a certain term */
            $cache_name = 'kml:term:' . $b;
            $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid INNER JOIN {location_instance} l ON n.vid = l.vid WHERE n.status = 1 AND tn.tid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
            $attributes['title'] = t('Tag: %tag', array(
              '%tag' => $tag,
            ));
            $attributes['description'] = t('Nodes tagged with %tag', array(
              '%tag' => $tag,
            ));
            _kml_feed_check_access($nodes, $attributes, $cache_name);
          }
        }
        else {
          drupal_not_found();
        }
      }
    }
    else {
      if ($a == 'group' && is_numeric($b)) {
        if (module_exists('og')) {
          $groupnode = node_load($b);
          if (og_is_group_type($groupnode->type)) {

            // TODO: check also to see if user is part of group
            $group_name = $groupnode->title;
            if ($c == 'networklink') {

              /* Network link for all location-enabled nodes in a certain group */
              $attributes['kml_feed'] = url('kml/group/' . $b . '/', array(
                'absolute' => TRUE,
              ));
              $attributes['title'] = t('Group: %group', array(
                '%group' => $group_name,
              ));
              $attributes['description'] = t('Nodes in %group', array(
                '%group' => $group_name,
              ));
              kml_networklink($attributes);
            }
            else {

              /* All location-enabled nodes in a certain group */
              $cache_name = 'kml:group:' . $b;
              $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid INNER JOIN {location_instance} l ON n.vid = l.vid WHERE n.status = 1 AND na.gid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
              $attributes['title'] = t('Group: %group', array(
                '%group' => $group_name,
              ));
              $attributes['description'] = t('Nodes in %group', array(
                '%group' => $group_name,
              ));
              _kml_feed_check_access($nodes, $attributes, $cache_name);
            }
          }
          else {
            drupal_not_found();
          }
        }
        else {
          drupal_not_found();
        }
      }
      else {
        if ($a == 'view' && $b) {
          if (module_exists('views')) {
            $b = check_plain($b);
            $view = module_invoke('views', 'get_view', $b);
            if ($view->url) {
              if ($c == 'networklink') {

                /* Network link for nodes in a view */
                if ($view->page_type == 'kml') {

                  // a view intended to be used as KML feed
                  $attributes['kml_feed'] = url($view->url . '/', array(
                    'absolute' => TRUE,
                  ));
                }
                else {

                  // any other view
                  $attributes['kml_feed'] = url('kml/view/' . $view->name . '/', array(
                    'absolute' => TRUE,
                  ));
                }
                $attributes['title'] = t('%view_title', array(
                  '%view_title' => $view->page_title,
                ));
                $attributes['description'] = t('%view_description', array(
                  '%view_description' => $view->description,
                ));
                kml_networklink($attributes);
              }
              else {

                /* Invoke views module to get the page defined by the view */
                if ($view->page_type == 'kml') {
                  print module_invoke('views', 'build_view', 'page', $view, $args);
                }
                else {
                  $nodes = module_invoke('views', 'build_view', 'items', $view, $args);
                  theme_kml_feed($view, $nodes['items'], 'page');
                }
              }
            }
            else {
              drupal_not_found();
            }
          }
          else {
            drupal_not_found();
          }
        }
        else {
          if ($a == 'search' && $b == 'node' && $c) {
            if (module_exists('search')) {
              $type = check_plain($b);
              $keys = check_plain($c);
              if ($d == 'networklink') {

                /* Network link for all nodes returned by a certain search */
                $attributes['kml_feed'] = url('kml/search/' . $type . '/' . $keys . '/', array(
                  'absolute' => TRUE,
                ));
                $attributes['title'] = t('Search: %terms', array(
                  '%terms' => $keys,
                ));
                $attributes['description'] = t('Nodes matching %terms', array(
                  '%terms' => $keys,
                ));
                kml_networklink($attributes);
              }
              else {

                /* All nodes returned by a certain search */
                $nodes = module_invoke($type, 'search', 'search', $keys);
                $attributes['title'] = t('Search: %terms', array(
                  '%terms' => $keys,
                ));
                $attributes['description'] = t('Nodes matching %terms', array(
                  '%terms' => $keys,
                ));
                _kml_feed($nodes, $attributes);
              }
            }
            else {
              drupal_not_found();
            }
          }
          else {
            if ($a == 'user') {

              // TODO: user locations
            }
            else {
              kml_page();
            }
          }
        }
      }
    }
  }
}