cvs diff: Diffing contrib/location_panels
Index: contrib/location_panels/location_panels.info
===================================================================
RCS file: contrib/location_panels/location_panels.info
diff -N contrib/location_panels/location_panels.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/location_panels/location_panels.info	18 May 2010 18:40:40 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Location Panels
+description = Integrate Location with Panels
+package = Location
+core = 6.x
+dependencies[] = location
+dependencies[] = panels
Index: contrib/location_panels/location_panels.module
===================================================================
RCS file: contrib/location_panels/location_panels.module
diff -N contrib/location_panels/location_panels.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/location_panels/location_panels.module	18 May 2010 18:26:42 -0000
@@ -0,0 +1,13 @@
+<?php 
+// $Id$
+
+/**
+ * Implement hook_ctools_plugin_directory().
+ */
+function location_panels_ctools_plugin_directory($module, $plugin)
+{
+  if ($module == 'ctools' && !empty($plugin)) {
+    return 'plugins/' . $plugin;
+  }
+}
+
cvs diff: Diffing contrib/location_panels/plugins
cvs diff: Diffing contrib/location_panels/plugins/content_types
Index: contrib/location_panels/plugins/content_types/country_name.inc
===================================================================
RCS file: contrib/location_panels/plugins/content_types/country_name.inc
diff -N contrib/location_panels/plugins/content_types/country_name.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/location_panels/plugins/content_types/country_name.inc	18 May 2010 18:56:33 -0000
@@ -0,0 +1,51 @@
+<?php
+// $Id$
+
+/**
+ * Callback function to supply a list of content types.
+ */
+function location_panels_country_name_ctools_content_types() {
+  return array(
+    'single' => TRUE,
+    'title' => t('Country name'),
+    'icon' => 'icon_node.png',
+    'description' => t('The name of the country.'),
+    'required context' => new ctools_context_required(t('Location'), 'location'),
+    'category' => t('Location'),
+  );
+}
+
+/**
+ * Render the location country name content type.
+ */
+function location_panels_country_name_content_type_render($subtype, $conf, $panel_args, $context) {
+  if (empty($context) || empty($context->data)) {
+    return;
+  }
+
+  // Get a shortcut to the location.
+  $location = $context->data;
+  
+  // Build the content type block.
+  $block = new stdClass();
+  $block->module = 'country_name';
+  $block->title = t('Country Name');
+  $block->content = $location['country_name'];
+  $block->delta = 0;
+
+  return $block;
+}
+
+/**
+ * Return an edit form for custom type settings.
+ */
+function location_panels_country_name_content_type_edit_form(&$form, &$form_state) {
+  // provide a blank form so we have a place to have context setting.
+}
+
+/**
+ * Return the administrative title for a type.
+ */
+function location_panels_country_name_content_type_admin_title($subtype, $conf, $context) {
+  return t('"@s" country name', array('@s' => $context->identifier));
+}
cvs diff: Diffing contrib/location_panels/plugins/contexts
Index: contrib/location_panels/plugins/contexts/location.inc
===================================================================
RCS file: contrib/location_panels/plugins/contexts/location.inc
diff -N contrib/location_panels/plugins/contexts/location.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/location_panels/plugins/contexts/location.inc	18 May 2010 18:37:17 -0000
@@ -0,0 +1,93 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Creates a location context.
+ */
+
+/**
+ * Implement hook_[context_name]_ctools_contexts().
+ */
+function location_panels_location_ctools_contexts() {
+  return array(
+    'title' => t('Location'),
+    'description' => t('Location'),
+    'context' => 'location_panels_context_create_location',
+    'context name' => 'location',
+    'settings form' => 'location_settings_form',
+    'keyword' => 'location',
+    'context name' => 'measure',
+    'convert list' => 'location_panels_context_location_convert_list',
+    'convert' => 'location_panels_context_location_convert',
+    'placeholder form' => array(
+      '#type' => 'textfield',
+      '#description' => t('Enter some data to represent this measure.'),
+  ),
+  );
+}
+
+/**
+ * Create a context, either from configuration or an argument on the URL.
+ *
+ * @param $empty
+ *   If true, just return an empty context.
+ * @param $data
+ *   If from settings form, a form values array. If from argument, a string.
+ * @param $conf
+ *   TRUE if the $data is coming from admin configuration, FALSE if it's
+ *   from a URL arg.
+ *
+ * @return
+ *   a Context object
+ */
+function location_panels_context_create_location($empty, $data = NULL, $conf = FALSE) {
+  $context = new ctools_context('location');
+  $context->plugin = 'location';
+
+  if ($empty) {
+    return $context;
+  }
+
+  if ($conf) {
+    $lid = is_array($data) && isset($data['lid']) ? $data['lid'] : (is_object($data) ? $data->lid : 0);
+    if (is_array($data) || !empty($reload)) {
+      $data = location_load_location($nid);
+    }
+  }
+
+  if (!empty($data))  {
+    $context->data = $data;
+    $context->title = $data['city'];
+    $context->argument = $data['lid'];
+    return $context;
+  }
+}
+
+function location_settings_form($conf, $external = FALSE) {
+  return array();
+}
+
+/**
+ * Provide a list of ways that this context can be converted to a string.
+ */
+function location_panels_context_location_convert_list() {
+  return array(
+    'country_code' => t('Country code'),
+    'country_name' => t('Country name'),
+  );
+}
+
+/**
+ * Convert a context into a string.
+ */
+function location_panels_context_location_convert($context, $type) {
+  switch ($type) {
+    case 'country_code':
+      return $context->data['country'];
+
+    case 'country_name':
+      return $context->data['country_name'];
+
+  }
+}
cvs diff: Diffing contrib/location_panels/plugins/relationships
Index: contrib/location_panels/plugins/relationships/location_from_node.inc
===================================================================
RCS file: contrib/location_panels/plugins/relationships/location_from_node.inc
diff -N contrib/location_panels/plugins/relationships/location_from_node.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ contrib/location_panels/plugins/relationships/location_from_node.inc	18 May 2010 18:56:07 -0000
@@ -0,0 +1,74 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Plugin to provide an relationship handler for location data from node.
+ */
+
+/**
+ * Implement hook_[relationship_name]_ctools_relationships().
+ */
+function location_panels_location_from_node_ctools_relationships() {
+  return array(
+    'title' => t('Node Location'),
+    'keyword' => 'location',
+    'description' => t('Creates a location for the node.'),
+    'required context' => new ctools_context_required(t('Node'), 'node'),
+    'context' => 'location_panels_location_from_node_context',
+    'settings form' => 'location_panels_location_from_node_settings_form',
+    'settings form validate' => 'location_panels_location_from_node_settings_form_validate',
+  );
+}
+
+/**
+ * Return a new ctools context based on an existing context.
+ */
+function location_panels_location_from_node_context($context, $conf) {
+  // If unset it wants a generic, unfilled context, which is just NULL.
+  if (empty($context->data)) {
+    $new_context = ctools_context_create_empty('location', NULL);
+  }
+  // See if the node itself contains location data, instead of Location CCK.
+  elseif (isset($context->data->location)) {
+    if ($location = location_load_location($context->data->location['lid'])) {
+      $new_context = ctools_context_create('location', $location);
+    }
+  }
+  // Otherwise, deal with Location CCK.
+  /// @TODO -- This is untested and probably broken at this point.
+  else {
+    $field = content_fields($conf['field_name']);
+    if (isset($context->data->{$conf['field_name']}[0]['lid'])) {
+      $lid = $context->data->{$conf['field_name']}[0]['lid'];
+      if ($location = location_load_location($lid)) {
+        $new_context = ctools_context_create('location', $location);
+      }
+    }
+  }
+  if (!empty($new_context)) {
+    return $new_context;
+  }
+}
+
+/**
+ * Settings form for the ctools relationship.
+ */
+function location_panels_location_from_node_settings_form($conf) {
+  $options = array();
+  foreach (content_fields() as $field) {
+    if ($field['type'] == 'location') {
+      $options[$field['field_name']] = t($field['widget']['label']);
+    }
+  }
+  $form['field_name'] = array(
+    '#title' => t('Location field'),
+    '#type' => 'select',
+    '#options' => $options,
+    '#default_value' => isset($conf['field_name']) ? $conf['field_name'] : '',
+    '#prefix' => '<div class="clear-block">',
+    '#suffix' => '</div>',
+  );
+
+  return $form;
+}
