From c927791561b24e58f89b060e980e417c1f72e22b Mon Sep 17 00:00:00 2001
From: Jaime Herencia <jherencia@360690.no-reply.drupal.org>
Date: Sat, 19 Jan 2013 00:27:33 +0100
Subject: [PATCH] Issue #1230146 by Valor, jherencia | wcarpent: Add Panels
 pane.

---
 plugins/content_types/sharethis/sharethis.inc |   71 +++++++++++++++++++++++++
 sharethis.module                              |    9 ++++
 2 files changed, 80 insertions(+)
 create mode 100644 plugins/content_types/sharethis/sharethis.inc

diff --git a/plugins/content_types/sharethis/sharethis.inc b/plugins/content_types/sharethis/sharethis.inc
new file mode 100644
index 0000000..0c65d75
--- /dev/null
+++ b/plugins/content_types/sharethis/sharethis.inc
@@ -0,0 +1,71 @@
+<?php
+
+$plugin = array(
+  'title' => t('ShareThis Widget'),
+  'description' => t('ShareThis Widget pane'),
+  'category' => t('Widgets'),
+  'defaults' => array(
+    'path' => 'global',
+    'path-external' => '',
+  ),
+);
+
+function sharethis_sharethis_content_type_render($subtype, $conf, $panel_args) {
+  if ($conf['path'] == 'external') {
+    $url = $conf['path-external'];
+  }
+  else {
+    $path = ($conf['path'] == 'global') ? '<front>' : $_GET['q'];
+    $url = url($path, array('absolute' => TRUE));
+  }
+  $title = ($conf['path'] == 'current') ? drupal_get_title() : variable_get('site_name', '');
+
+  $block = new stdClass();
+  $block->module  = 'sharethis';
+  $block->content = sharethis_get_button_HTML(sharethis_get_options_array(), $url, $title);
+
+  return $block;
+}
+
+function sharethis_sharethis_content_type_edit_form($form, &$form_state) {
+  $conf = $form_state['conf'];
+  $description =  t('Variable - Different per URL');
+  $description .= '<br />';
+  $description .= t('External - Useful in iframes (Facebook Tabs, etc.)');
+  $form['path'] = array(
+    '#type' => 'select',
+    '#title' => t('Path to share'),
+    '#options' => array(
+      'global' => t('Global'),
+      'current' => t('Variable'),
+      'external' => t('External URL'),
+    ),
+    '#description' => $description,
+    '#default_value' => $conf['path'],
+  );
+
+  $form['path-external'] = array(
+    '#type' => 'textfield',
+    '#title' => t('External URL'),
+    '#default_value' => $conf['path-external'],
+    '#states' => array(
+      'visible' => array(
+        ':input[name="path"]' => array('value' => 'external'),
+      ),
+    ),
+  );
+
+  return $form;
+}
+
+function sharethis_sharethis_content_type_edit_form_validate($form, &$form_state) {
+  if (($form_state['values']['path'] == 'external') && (!valid_url($form_state['values']['path-external'], TRUE))) {
+    form_set_error('path-external', t('Invalid URL'));
+  }
+}
+
+function sharethis_sharethis_content_type_edit_form_submit($form, &$form_state) {
+  foreach (array('path', 'path-external') as $key) {
+    $form_state['conf'][$key] = $form_state['values'][$key];
+  }
+}
diff --git a/sharethis.module b/sharethis.module
index afe81bf..1e2d365 100644
--- a/sharethis.module
+++ b/sharethis.module
@@ -580,3 +580,12 @@ function sharethis_views_api() {
     'path' => drupal_get_path('module', 'sharethis') . '/views',
   );
 }
+
+**
+ * Implementation of hook_ctools_plugin_directory
+ */
+function sharethis_ctools_plugin_directory($module, $plugin) {
+  if ($module == 'panels' || $module == 'ctools') {
+    return 'plugins/' . $plugin;
+  }
+}
-- 
1.7.9.6 (Apple Git-31.1)

