summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.txt60
-rwxr-xr-xaddthis.admin.css6
-rw-r--r--addthis.admin.inc377
-rw-r--r--addthis.info6
-rw-r--r--addthis.install40
-rw-r--r--addthis.module378
-rw-r--r--addthis.views.inc24
-rwxr-xr-xaddthis_handler_field.inc83
-rw-r--r--addthis_handler_field_service_links.inc43
-rw-r--r--at_cck_field/at_cck_field.info6
-rw-r--r--at_cck_field/at_cck_field.install40
-rw-r--r--at_cck_field/at_cck_field.module441
-rw-r--r--at_content_type/at_content_type.info8
-rw-r--r--at_content_type/at_content_type.module79
-rw-r--r--at_export/at_export.info6
-rw-r--r--at_export/at_export.module44
-rw-r--r--at_taxonomy/at_taxonomy.info6
-rw-r--r--at_taxonomy/at_taxonomy.module81
-rwxr-xr-xat_visibility/at_visibility.info8
-rwxr-xr-xat_visibility/at_visibility.install36
-rwxr-xr-xat_visibility/at_visibility.module213
21 files changed, 1621 insertions, 364 deletions
diff --git a/README.txt b/README.txt
index a299a92..2b9cd48 100644
--- a/README.txt
+++ b/README.txt
@@ -1,56 +1,30 @@
-/* $Id$ */
+Installing AddThis
--- SUMMARY --
+Copy the module in sites/all/modules/
-Add This module provides Drupal integration to addthis.com link sharing service.
-Description from addthis.com:
-The AddThis button spreads your content across the Web by making it easier for your visitors to bookmark and
-share it with other people, again... and again... and again. This simple yet powerful button is very easy to
-install and provides valuable Analytics about the bookmarking and sharing activity of your users. AddThis helps
-your visitors create a buzz for your site and increase its popularity and ranking.
+Basic usage
-AddThis is already on hundreds of thousands of websites including SAP, TIME Magazine, Oracle, Freewebs,
-Entertainment Weekly, Topix, Lonely Planet, MapQuest, MySpace, PGA Tour, Tower Records, Squidoo, Zappos, Funny
-or Die, FOX, ABC, CBS, Glamour, PostSecret, WebMD, American Idol, and ReadWriteWeb, just to name a few. Each
-month our button is displayed 20 billion times.
+Navigate to administer >> build >> modules. Enable AddThis module. No other modules from the AddThis package is needed.
+Set AddThis widget settings in admin/settings/addthis. Set visibility settings in admin/settings/addthis/visibility.
--- REQUIREMENTS --
-None.
+Advanced usage
--- INSTALLATION --
+Navigate to administer >> build >> modules. Enable AddThis module and additional modules from AddThis package. Additional modules
+will bring more options to the AddThis visibility settings form.
-Normal Drupal module installation, see http://drupal.org/node/70151 for further information.
+The most important visibility setting is Visibility type, which can take two values: allow or disallow.
-For link sharing statistics registration at http://addthis.com/ is required, but the module will work even without registration.
+By setting Visibility type to allow ONLY nodes that satisfy rules defined by additional modules from AddThis package
+will have AddThis links.
--- CONFIGURATION --
+By setting Visibility type to disallow every node will have AddThis links EXCEPT those nodes which satisfy rules defined
+by additional modules from the AddThis package.
-There are two ways of using the module:
-1) Display AddThis button in node links.
-* Go to Administer / Site configuration / AddThis.
-* Check Display on node pages.
-* Optionally check Display in node teasers.
-* If you want to limit AddThis visibility by content type go to Administer / Content management / Content types and choose a content type. Visibility can be set for each content type under Workflow settings.
-
-2) Use AddThis as a block.
-* Go to Site building / Blocks and make AddThis button block visible.
-
--- CUSTOMIZATION --
-
-You have a number of options available at Administer / Site configuration / Addthis under Button image settings
- and Widget settings. Image settings control the button image and widget controls the drop down and window that is opened when user clicks on a link sharing service. More information on how to customize your AddThis button can be found at http://addthis.com/help/customize/custom-button/
-
-If configuration options are not flexible enough for you it is also possible to override theme_addthis_button in your own theme.
-
--- ROADMAP --
-
-Future development of this module will include at least RSS support. CCK and Views integration may be included in future releases. Drupal 5.x version will no longer get any new features. Drupal 7.x version will be released soon after D7 code freeze.
-
--- CONTACT --
-
-Current maintainers:
-* Vesa Palmu (wesku) - http://drupal.org/user/75070
+Implementing additional AddThis modules
+If you are interested in implementing additional modules to create new visibility rules for the AddThis links your module
+needs to define hook_restrict. The return value of the hook has to be TRUE if the rule is satisfied and FALSE otherways.
+AddThis module decides should the AddThis links be displayed based on all the visibility rules and Visibility type setting.
diff --git a/addthis.admin.css b/addthis.admin.css
new file mode 100755
index 0000000..47a817d
--- /dev/null
+++ b/addthis.admin.css
@@ -0,0 +1,6 @@
+/* $Id$ */
+
+.addthis_service_icon {
+ display: inline-block;
+ padding-left: 20px;
+} \ No newline at end of file
diff --git a/addthis.admin.inc b/addthis.admin.inc
index f963208..5e13789 100644
--- a/addthis.admin.inc
+++ b/addthis.admin.inc
@@ -3,154 +3,253 @@
/**
* @file
- * Administration settings for AddThis button integration
+ * Admin forms for Addthis settings
*/
/**
- * Administration settings form.
- *
- * @return
- * The completed form definition.
+ * Return a form object for default AddThis settings.
*/
-function addthis_admin_settings() {
- $form = array();
+function addthis_config_form() {
+ // Load the external AddThis CSS file for displaying service icons.
+ // TODO: Optionally cache the CSS file and icons sprite locally
+ drupal_set_html_head('<link rel="stylesheet" href="http://cache.addthiscdn.com/icons/v1/sprites/services.css" type="text/css" />');
+ drupal_add_css(drupal_get_path('module', 'addthis') .'/addthis.admin.css');
- $form['addthis_general_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('General settings'),
+ // Select widget type.
+ $form['addthis_widget_select'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Widget type'),
+ );
+ $form['addthis_widget_select']['addthis_widget_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('AddThis widget type'),
+ '#options' => array(
+ 'addthis_button' => t('Button'),
+ 'addthis_toolbox' => t('Toolbox'),
+ ),
+ '#default_value' => variable_get('addthis_widget_type', 'addthis_button'),
);
- $form['addthis_general_settings']['addthis_username'] = array(
- '#type' => 'textfield',
- '#title' => t('Username'),
- '#default_value' => variable_get('addthis_username', 'my-username'),
- '#description' => t('Your username for <a href="http://www.addthis.com/">addthis.com</a>. Example: my-username'),
+
+ // Settings for the addthis_config javascript object.
+ // See http://addthis.com/help/menu-api#configuration-ui for details.
+ $addthis_config = variable_get('addthis_config', array());
+ $form['addthis_config'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Widget settings'),
+ '#tree' => TRUE,
+ );
+ $form['addthis_config']['services_compact'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Short list of services'),
+ '#description' => t('A comma-separated list of service codes that determines which services will be shown in the dropdown or toolbox.<br />This list can also take two special, non-service codes:<br /><strong>more</strong> - Displays a button that opens the expanded service menu.<br /><strong>separator</strong> - Toolbox only. Renders a separator that can be placed between toolbox items.'),
+ '#rows' => 2,
+ '#default_value' => $addthis_config['services_compact'],
+ '#wysiwyg' => FALSE,
+ '#element_validate' => array('_addthis_validate_services_compact'),
+ );
+ $form['addthis_config']['services_expanded'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Expanded services'),
+ '#description' => t('A comma-separated list of service codes that determines which services will be shown in the expanded menu, if enabled. Leave blank to make all services available.'),
+ '#rows' => 2,
+ '#default_value' => $addthis_config['services_expanded'],
+ '#wysiwyg' => FALSE,
+ );
+ $form['addthis_config']['services_help'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('List of available service codes'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['addthis_config']['services_help']['services_list'] = array(
+ '#type' => 'markup',
+ '#prefix' => l(t('Refresh this list.'), 'admin/settings/addthis/flush-cache', array('query' => drupal_get_destination())),
+ '#value' => _addthis_services_list(),
+ );
+ $form['addthis_config']['ui_cobrand'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Branding'),
+ '#description' => t('Custom text displayed in the top-right of the AddThis menu. This should probably be less than 15 characters to fit.'),
+ '#default_value' => $addthis_config['ui_cobrand'],
+ );
+ $form['addthis_config']['username'] = array(
+ '#type' => 'textfield',
+ '#title' => t('AddThis username'),
+ '#description' => t('Optional. If you are using AddThis Analytics, enter the username of the AddThis account where you are collecting AddThis click data.'),
+ '#default_value' => $addthis_config['username'],
+ );
+ /*
+ $form['addthis_config']['color_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Color settings',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ */
+ $form['addthis_config']['ui_header_color'] = array(
+ '#type' => (module_exists('colorpicker') ? 'colorpicker_' : '') . 'textfield',
+ '#title' => t('Header color'),
+ '#description' => t('Optional. The color to use for the text foreground in
+ the header of the compact (on-hover) menu and lightbox, in hex.'
+ .(module_exists('colorpicker') ? '' : ' Download colorpicker module for more user friendly selection of the color.')),
+ '#default_value' => ($addthis_config['ui_header_color'] ? $addthis_config['ui_header_color'] : '#000000'),
+ );
+ $form['addthis_config']['ui_header_background'] = array(
+ '#type' => (module_exists('colorpicker') ? 'colorpicker_' : '') . 'textfield',
+ '#title' => t('Header background'),
+ '#description' => t('The color to use as a background in the header of the compact (on-hover) menu and lightbox, in hex.'
+ .(module_exists('colorpicker') ? '' : ' Download colorpicker module for more user friendly selection of the color.')),
+ '#default_value' => ($addthis_config['ui_header_background'] ? $addthis_config['ui_header_background'] : '#FFFFFF'),
+ );
+ $form['addthis_config']['ui_click'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Disable opening AddThis on mouse hover'),
+ '#description' => t('If checked, the AddThis dialog will only open if the AddThis button is clicked. Otherwise, the dialog will open when the mouse hovers over it.'),
+ '#return_value' => TRUE,
+ '#default_value' => $addthis_config['ui_click'],
+ );
+ $form['addthis_config']['ui_delay'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Hover delay'),
+ '#size' => 5,
+ '#element_validate' => array('_addthis_validate_ui_delay'),
+ '#description' => t('Delay, in milliseconds, before the compact menu appears when mousing over a regular button. Capped at 500 ms.'),
+ '#default_value' => $addthis_config['ui_delay'],
+ );
+ $form['addthis_config']['data_track_clickback'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Allow AddThis to track incoming traffic from shares'),
+ '#description' => t('If checked, AddThis will collect data on how many people come back to your content via links shared with AddThis.'),
+ '#return_value' => TRUE,
+ '#default_value' => $addthis_config['data_track_clickback'],
+ );
+ $form['addthis_config']['ui_use_addressbook'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Allow AddThis to import contacts for email sharing'),
+ '#description' => t('If checked, the user will be able import their contacts from popular webmail services when using email sharing.'),
+ '#return_value' => TRUE,
+ '#default_value' => $addthis_config['ui_use_addressbook'],
+ );
+ /**
+ * Setting 'ui_508_compliant' doesn't seem to do anything. An API bug?
+ *
+ $form['addthis_config']['ui_508_compliant'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Section 508 compliance mode'),
+ '#description' => t('If checked, clicking the AddThis button will open a new window to a page supporting sharing without JavaScript.'),
+ '#return_value' => TRUE,
+ '#default_value' => $addthis_config['ui_508_compliant'],
+ );
+ */
+ return system_settings_form($form);
+}
+
+/*
+ * Return a form object for addthis visibilituy settings
+ */
+function addthis_visibility_config_form() {
+ // Drupal visibility settings for AddThis.
+ $form['addthis_visibility'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('AddThis visibility settings'),
+ '#description' => t('AddThis can also be displayed as a block, which you can configure on the <a href="!url">block administration page.</a>', array('!url' => url('admin/build/block'))),
);
- $form['addthis_general_settings']['addthis_display_in_links'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display on node pages'),
+
+ // This form element controls visibility rules allowing or disallowing showing of addthis links
+ // TODO this must be shown only if there exists hooks implementing restrict hook
+ if (module_implements('restrict')) {
+ $options = array(t('allow') => 'allow', t('disallow') => 'disallow');
+ $form['addthis_visibility']['addthis_visibility_type'] = array(
+ '#type' => 'select',
+ '#title' => t('Visibility type'),
+ '#options' => $options,
+ '#default_value' => variable_get('addthis_visibility_type', 'restrict'),
+ '#description' => t('Select whether the settings are used to allow or disallow displaying of addthis links. Currently
+ following modules implement restrict -hook ').implode(", ",module_implements('restrict')).'.',
+ );
+ }
+
+ $form['addthis_visibility']['addthis_display_in_links'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display in full nodes'),
'#default_value' => variable_get('addthis_display_in_links', '0'),
- '#description' => t('Display an AddThis button always on a node page\'s links section.'),
+ '#description' => t('Display the widget in the links section of a node when viewing the full node.'),
);
- $form['addthis_general_settings']['addthis_display_in_teasers'] = array(
- '#type' => 'checkbox',
- '#title' => t('Display in node teasers'),
+ $form['addthis_visibility']['addthis_display_in_teasers'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display in node teasers'),
'#default_value' => variable_get('addthis_display_in_teasers', '0'),
- '#description' => t('Display an AddThis button in the node teasers.'),
- );
-
- $form['addthis_button_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Button image settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['addthis_button_settings']['addthis_image'] = array(
- '#type' => 'textfield',
- '#title' => t('Button image url'),
- '#default_value' => variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
- '#description' => t('URL for small image in the button. Example: http://s9.addthis.com/button1-share.gif'),
- );
- $form['addthis_button_settings']['addthis_image_secure'] = array(
- '#type' => 'textfield',
- '#title' => t('Button image url for secure https connection'),
- '#default_value' => variable_get('addthis_image_secure', 'https://secure.addthis.com/button1-share.gif'),
- '#description' => t('This is only required if your site uses secure https connections. Example: https://secure.addthis.com/button1-share.gif'),
- );
- $form['addthis_button_settings']['addthis_image_width'] = array(
- '#type' => 'textfield',
- '#title' => t('Button image width'),
- '#default_value' => variable_get('addthis_image_width', '125'),
- '#description' => t('Width for button image. Example: 125'),
- );
- $form['addthis_button_settings']['addthis_image_height'] = array(
- '#type' => 'textfield',
- '#title' => t('Button image height'),
- '#default_value' => variable_get('addthis_image_height', '16'),
- '#description' => t('Height for button image. Example: 16'),
- );
- $form['addthis_button_settings']['addthis_image_attributes_alt'] = array(
- '#type' => 'textfield',
- '#title' => t('Button image Alt tag'),
- '#default_value' => variable_get('addthis_image_attributes_alt', 'share'),
- '#description' => t('Text for Alt tag in img tag. Default: share'),
- );
- $form['addthis_button_settings']['addthis_image_attributes_class'] = array(
- '#type' => 'textfield',
- '#title' => t('Button image Class tag'),
- '#default_value' => variable_get('addthis_image_attributes_class', 'addthisimage'),
- '#description' => t('Text for CSS class in img tag. Default: addthisimage'),
- );
- $form['addthis_widget_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Widget settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form['addthis_widget_settings']['addthis_dropdown_disabled'] = array(
- '#type' => 'checkbox',
- '#title' => t('Disable dropdown'),
- '#default_value' => variable_get('addthis_dropdown_disabled', '0'),
- '#description' => t('You can disable the dropdown for selecting where to share your link and use a pop-up window instead. This can be useful if the button is for example located next to a flash object.'),
- );
- $form['addthis_widget_settings']['addthis_logo'] = array(
- '#type' => 'textfield',
- '#title' => t('Logo url'),
- '#default_value' => variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
- '#description' => t('The logo to display on the popup window (about 200x50 pixels). The popup window is show when the user selects the \'More\' choice. Example: http://www.your-website.com/img/mylogo.gif'),
- );
- $form['addthis_widget_settings']['addthis_logo_background'] = array(
- '#type' => 'textfield',
- '#title' => t('Logo background color'),
- '#default_value' => variable_get('addthis_logo_background', 'EFEFFF'),
- '#description' => t('The color to use as a background around the logo in the popup. Example: EFEFEF'),
- );
- $form['addthis_widget_settings']['addthis_logo_color'] = array(
- '#type' => 'textfield',
- '#title' => t('Logo text color'),
- '#default_value' => variable_get('addthis_logo_color', '666699'),
- '#description' => t('The color to use for the text next to the logo in the popup. Example: 666666'),
- );
- $form['addthis_widget_settings']['addthis_brand'] = array(
- '#type' => 'textfield',
- '#title' => t('Brand text'),
- '#default_value' => variable_get('addthis_brand', ''),
- '#description' => t('The brand name to display in the drop-down (top right). Example: My Website. Leave blank to use the site_name variable, currently set to !site_name', array('!site_name' => variable_get('site_name', 'Drupal'))),
- );
- $form['addthis_widget_settings']['addthis_options'] = array(
- '#type' => 'textarea',
- '#title' => t('Options'),
- '#default_value' => variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
- '#description' => t('A comma-separated ordered list of options to include in the drop-down. Example: favorites, email, digg, delicious, more<br/>Currently supported options:<br/>
- aim, aolfav, ask, backflip, ballhype, blinklist, blogmarks, bluedot, buzz, delicious, digg, diigo, email, facebook, favorites, fark, feedmelinks, friendfeed, furl, google, kaboodle, kirtsy, linkedin, live, magnolia, misterwong, mixx, multiply, myweb, myspace, netvous, newsvine, pownce, propeller, reddit, segnalo, sharedstuff, slashdot, spurl, stumbleupon, stylehive, tailrank, technorati, thisnext, twitter, yardbarker, yahoobkm, more<br />
- The most up-to-date list can be found <a href="!url">here</a>.', array('!url' => url('http://addthis.com/services/list'))),
- );
- $form['addthis_widget_settings']['addthis_offset_top'] = array(
- '#type' => 'textfield',
- '#title' => t('Offset top'),
- '#default_value' => variable_get('addthis_offset_top', '2'),
- '#description' => t('Vertical offset for the drop-down window (in pixels). Example: 2'),
- );
- $form['addthis_widget_settings']['addthis_offset_left'] = array(
- '#type' => 'textfield',
- '#title' => t('Offset top'),
- '#default_value' => variable_get('addthis_offset_left', '2'),
- '#description' => t('Horizontal offset for the drop-down window (in pixels). Example: 2'),
- );
- $form['addthis_widget_settings']['addthis_disable_flash'] = array(
- '#type' => 'checkbox',
- '#title' => t('Disable Flash cookie'),
- '#default_value' => variable_get('addthis_disable_flash', '0'),
- '#description' => t('AddThis.com uses Flash cookies by default to <a href="http://www.addthis.com/blog/2009/01/05/the-addthis-flash-cookie-we-need-your-feedback/">provide more accurate tracking information</a>. Some people consider this <a href="http://drupal.org/node/364078">a privacy concern</a> and Flash cookies can be replaced with normal ones by checking this checkbox.'),
- );
- $form['addthis_widget_settings']['addthis_widget_version'] = array(
- '#type' => 'select',
- '#title' => t('Widget Version'),
- '#default_value' => variable_get('addthis_widget_version', '152'),
- '#options' => array(
- 152 => t('152 - Uses a popup window for the more option'),
- 200 => t('200 - Adds lightbox support for the more option')
- ),
- '#description' => t('The version of the addthis widget to use.'),
+ '#description' => t('Display the widget in the links section of a node when viewing it as a teaser.'),
);
+
return system_settings_form($form);
-} \ No newline at end of file
+}
+
+/**
+ * Returns an array of AddThis service codes and names.
+ */
+function _addthis_services_list() {
+ // Retrieve the services table from the cache. If the cache is not set, get
+ // the list of services from AddThis and cache the results.
+ // See http://www.addthis.com/help/services-api
+ if (!$services_cache = cache_get('addthis:services')) {
+ $location = "http://cache.addthiscdn.com/services/v1/sharing.en.json";
+ $result = drupal_http_request($location);
+ if ($result->code == 200) {
+ $data = json_decode($result->data, TRUE);
+ $rows = array();
+ foreach ($data['data'] AS $service) {
+ //$service['code'] = '<script type="text/javascript">alert("xss")</script>';
+ $counter++;
+ $rows[] = array(
+ 0 => check_plain($service['code']),
+ 1 => '<span class="addthis_service_icon icon_' . check_plain($service['code']) . '"></span> ' . check_plain($service['name'])
+ );
+ }
+ $header = array(t('Service code'), t('Service'));
+ $services = theme('table', $header, $rows);
+ // disabling cache (in order to not to save check_plain values into database)
+ // TODO save service codes without any HTML to cache in order to do this properly
+ // cache_set('addthis:services', $services);
+ }
+ else {
+ drupal_set_message(t('The list of AddThis services could not be retrieved. Please try again later.'), 'error');
+ $services = FALSE;
+ }
+ }
+ else {
+ $services = $services_cache->data;
+ }
+
+ return $services;
+}
+
+/**
+ * Flush the services cache.
+ */
+function addthis_flush_cache() {
+ cache_clear_all('addthis:services', 'cache');
+ if (_addthis_services_list()) {
+ drupal_set_message(t('The list of AddThis services has been refreshed.'));
+ }
+ drupal_goto();
+}
+
+/**
+ * Checks whether ui_delay stays is a number between 0 and 500.
+ */
+function _addthis_validate_ui_delay($element, &$form_state) {
+ $value = $element['#value'];
+ if ($value && (!is_numeric($value) || $value < 0 || $value > 500)) {
+ form_error($element, t('%name must be a number between 0 and 500.', array('%name' => $element['#title'])));
+ }
+}
+
+/**
+ * If the toolbox is chosen, checks whether services have been set.
+ */
+function _addthis_validate_services_compact($element, &$form_state) {
+ if ($form_state['values']['addthis_widget_type'] == 'addthis_toolbox' && empty($element['#value'])) {
+ form_error($element, t('You must define a list of services if the AddThis Toolbox is selected.'));
+ }
+}
diff --git a/addthis.info b/addthis.info
index e255e29..355fa39 100644
--- a/addthis.info
+++ b/addthis.info
@@ -1,4 +1,6 @@
; $Id$
name = AddThis
-description = Creates AddThis button as a block, to be used in themes and to node links.
-core = 6.x \ No newline at end of file
+description = Implements AddThis Button functionality.
+core = 6.x
+
+package = "Bookmarking and sharing" \ No newline at end of file
diff --git a/addthis.install b/addthis.install
index c68736f..bd3987d 100644
--- a/addthis.install
+++ b/addthis.install
@@ -3,16 +3,36 @@
/**
* @file
- * Install, update and uninstall functions for the AddThis module.
+ * Remove variables on uninstall
*/
-/**
- * Implementation of hook_uninstall().
- */
-function addthis_uninstall() {
- // Remove module variables.
- $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'addthis_%'");
- while ($var_name = db_result($result)) {
- variable_del($var_name);
+/*
+function addthis_uninstall(){
+
+ $addthis_variables = _addthis_get_variables();
+}
+
+function addthis_update_6300() {
+
+ $nodetypes = node_get_types('names');
+ foreach($nodetypes as $type) {
+ variable_del('addthis_'.$type);
+ }
+
+}
+
+function _addthis_get_variables($str) {
+
+ $query = "SELECT name FROM {variable} WHERE name LIKE '".$str."%'";
+ $result = db_query($query);
+
+ $variable_names = array();
+ while($row=db_fetch_array($result)) {
+ $variable_names[] = $row['name'];
}
-} \ No newline at end of file
+
+ drupal_set_message(dsm($variable_names));
+ return $variable_names;
+}
+*/
+
diff --git a/addthis.module b/addthis.module
index 24866b6..cec746e 100644
--- a/addthis.module
+++ b/addthis.module
@@ -3,53 +3,95 @@
/**
* @file
- * Stand alone module file to handle AddThis button integration
+ * Integration to Addthis.com bookmarking & sharing service
*/
/**
+ * Implementation of hook_menu().
+ */
+function addthis_menu() {
+ $items = array();
+ $items['admin/settings/addthis'] = array(
+ 'title' => 'AddThis',
+ 'description' => 'Configuration settings for AddThis integration.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('addthis_config_form'),
+ 'access arguments' => array('administer addthis'),
+ 'file' => 'addthis.admin.inc',
+ );
+ $items['admin/settings/addthis/widget'] = array(
+ 'title' => 'AddThis widget settings',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
+ $items['admin/settings/addthis/visibility'] = array(
+ 'title' => 'AddThis visibility settings',
+ 'type' => MENU_LOCAL_TASK,
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('addthis_visibility_config_form'),
+ 'access arguments' => array('administer addthis'),
+ 'file' => 'addthis.admin.inc',
+ 'weight' => -9,
+ );
+
+ return $items;
+}
+
+/**
* Implementation of hook_perm().
*/
function addthis_perm() {
$perms[] = 'administer addthis';
- $perms[] = 'view addthis';
return $perms;
}
/**
* Implementation of hook_link().
*/
-function addthis_link($type, $node=NULL, $teaser = FALSE) {
- $links = array();
-
- if ($type === 'node' && user_access('view addthis')) {
- if (($node && variable_get('addthis_nodetype_' . $node->type, 1)) &&
- (($teaser && variable_get('addthis_display_in_teasers', '0')) ||
- (!$teaser && variable_get('addthis_display_in_links', '0')))) {
- $links['addthis'] = array(
- 'title' => _addthis_create_button($node, $teaser),
- 'html' => TRUE,
- );
- }
+function addthis_link($type, $node = NULL, $teaser = FALSE) {
+ $links = array();
+
+ // Is the button visible on this node
+ if (addthis_show_addthis($type, $node, $teaser)) {
+ $addthis_widget_type = variable_get('addthis_widget_type', 'addthis_button');
+ $links['addthis'] = array(
+ 'title' => theme($addthis_widget_type, NULL, array(
+ 'url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+ 'title' => check_plain($node->title),
+ )),
+ 'html' => TRUE,
+ );
}
return $links;
}
+
/**
- * Implementation of hook_menu().
+ * Decide whether addthis links will be displayed or not
+ *
+ * @return boolean
+ * returns TRUE if addthis links will be displayed
*/
-function addthis_menu() {
- $items = array();
+function addthis_show_addthis($type = 'node', $node = NULL, $teaser = FALSE){
- $items['admin/settings/addthis'] = array(
- 'title' => 'AddThis',
- 'description' => 'Set username and customize look and feel for <a href="http://www.addthis.com/">AddThis</a> button.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('addthis_admin_settings'),
- 'access arguments' => array('administer addthis'),
- 'file' => 'addthis.admin.inc',
- );
+ $show = array();
+ $show = module_invoke_all('restrict', $node);
- return $items;
+ // By default addthis button will be associated with every node. Default visibility
+ // type disallow means users can just hide the button on certain nodes.
+ $addthis_visibility_type = variable_get('addthis_visibility_type', 'disallow');
+
+ // TODO: What if we want to limit visibility based on something else than a node?
+ if ($type === 'node' && ($addthis_visibility_type == 'disallow' && in_array(TRUE, $show) == FALSE) ||
+ ($addthis_visibility_type === 'allow' && in_array(TRUE, $show) == TRUE)) {
+
+ if ( ($teaser && variable_get('addthis_display_in_teasers', '0')) ||
+ (!$teaser && variable_get('addthis_display_in_links', '0')) ) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
}
/**
@@ -60,136 +102,230 @@ function addthis_block($op = 'list', $delta = 0) {
$blocks[0]['info'] = t('AddThis button');
return $blocks;
}
- elseif ($op == 'view' && user_access('view addthis')) {
+ elseif ($op == 'view') {
+ $addthis_widget_type = variable_get('addthis_widget_type', 'addthis_button');
$block['subject'] = t('AddThis');
- $block['content'] = _addthis_create_button();
+ $block['content'] = theme($addthis_widget_type);
return $block;
}
}
/**
- * Implementation of hook_form_alter().
- */
-function addthis_form_alter(&$form, $form_state, $form_id) {
- if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
- $form['workflow']['addthis_nodetype'] = array(
- '#type' => 'checkbox',
- '#title' => t('Show AddThis button on this type of node'),
- '#default_value' => variable_get('addthis_nodetype_' . $form['#node_type']->type, 1),
- '#description' => t('Select whether the AddThis button should be shown or not on this type of node.'),
- );
- }
-}
-
-/**
* Implementation of hook_theme().
+ *
+ * addthis_button is an object consisting of one image
+ *
+ * addthis_toolbox is an object consisting of multiple images
+ *
+ * addthis_toolbox_item presents one image in addthis toolbox
*/
function addthis_theme() {
return array(
'addthis_button' => array(
'arguments' => array(
- 'node' => NULL,
- 'teaser' => NULL,
+ 'html' => NULL,
+ 'config' => array(),
+ ),
+ ),
+ 'addthis_toolbox' => array(
+ 'arguments' => array(
+ 'services' => NULL,
+ 'config' => array(),
+ 'more_text' => NULL,
+ ),
+ ),
+ 'addthis_toolbox_item' => array(
+ 'arguments' => array(
+ 'service' => NULL,
+ 'title' => NULL,
),
),
);
}
/**
- * Implementation of hook_views_api().
+ * Theme function to render an AddThis button.
+ *
+ * @param $html
+ * HTML code to be placed inside the <a> element that will become the AddThis
+ * button. If blank, AddThis will use its own default button image.
+ * @param array $config
+ * An optional array of configuration options to apply to this instance of
+ * the button. A list of key/value possibilities can be found at
+ * http://addthis.com/help/menu-api. Options from both addthis_config and
+ * addthis_share may be used.
*/
-function addthis_views_api() {
- return array(
- 'api' => 2,
- 'path' => drupal_get_path('module', 'addthis'),
- );
+function theme_addthis_button($html = NULL, $config = array()) {
+ addthis_add_default_js();
+ // Build the button attributes, including those provided in $config.
+ $attributes = array('class' => 'addthis_button');
+ if (!empty($config) && is_array($config)) {
+ foreach ($config AS $key => $value) {
+ $attributes['addthis:' . $key] = $value;
+ }
+ }
+ /* TODO: Requires some documentation */
+ $output = l(filter_xss_admin($html), NULL, array('html' => TRUE, 'attributes' => $attributes));
+
+ return $output;
}
/**
- * Internal function to generate code for AddThis button
+ * Theme function to render an AddThis toolbox.
*
- * @return
- * String containing html code for the button
+ * @param $services
+ * A comma-separated string of AddThis service codes to be rendered in the
+ * toolbox. If blank, the short list from the admin settings will be used.
+ * @param array $config
+ * An optional array of configuration options inherited by each item in the
+ * toolbox. A list of key/value possibilities can be found at
+ * http://addthis.com/help/menu-api
*/
-function _addthis_create_button($node=NULL, $teaser = FALSE) {
- global $_addthis_counter;
- $_addthis_counter++;
- $brand = variable_get('addthis_brand', '');
- if ($brand == '') {
- $brand = variable_get('site_name', 'Drupal');
+function theme_addthis_toolbox($services = NULL, $config = array(), $more_text = 'Share') {
+ if (empty($services)) {
+ $default_config = variable_get('addthis_config', array());
+ $services = explode(',', $default_config['services_compact']);
}
- if ($_addthis_counter == 1) {
- drupal_add_css((drupal_get_path('module', 'addthis') .'/addthis.css'));
- drupal_add_js(sprintf('
- addthis_pub = \'%s\';
- addthis_logo = \'%s\';
- addthis_logo_background = \'%s\';
- addthis_logo_color = \'%s\';
- addthis_brand = \'%s\';
- addthis_options = \'%s\';
- addthis_disable_flash = \'%s\';
- ',
- addslashes(check_plain(variable_get('addthis_username', 'my-username'))),
- addslashes(check_plain(variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'))),
- addslashes(check_plain(variable_get('addthis_logo_background', 'EFEFFF'))),
- addslashes(check_plain(variable_get('addthis_logo_color', '666699'))),
- addslashes(check_plain($brand)),
- addslashes(check_plain(variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'))),
- variable_get('addthis_options', FALSE) ? 'true' : 'false'
- ), 'inline');
+ foreach ($services AS $service) {
+ $service = trim($service);
+ switch ($service) {
+ case 'more':
+ $output .= theme('addthis_toolbox_item', 'expanded', $more_text);
+ break;
+ default:
+ $output .= theme('addthis_toolbox_item', $service);
+ }
}
+ // if a $config is specified, process it into $attributes.
+ if (!empty($config) && is_array($config)) {
+ foreach ($config AS $key => $value) {
+ $attributes .= sprintf("addthis:%s='%s' ", check_plain($key), check_plain($value));
+ }
+ }
+ return "<div class='addthis_toolbox addthis_default_style' $attributes>" . $output . "</div>";
+}
- return theme('addthis_button', $node, $teaser);
+/**
+ * Theme function to render an individual toolbox item. This is often, but not
+ * necessarily, in the context of an AddThis toolbox.
+ *
+ * @param service
+ * An AddThis service code. Full list at http://addthis.com/services/all
+ * @param $title
+ * Optional text to include inside the toolbox item link element.
+ */
+function theme_addthis_toolbox_item($service, $title = '') {
+ addthis_add_default_js();
+ switch ($service) {
+ case "separator":
+ $output = '<span class="addthis_separator">|</span>';
+ break;
+ default:
+ $output = '<a class="addthis_button_' . check_plain($service) . '">' . check_plain($title) . '</a>';
+ }
+ return $output;
}
/**
- * Theme the AddThis button.
+ * Load the addthis_widget.js and the configured AddThis defaults.
*/
-function theme_addthis_button($node, $teaser) {
- global $_addthis_counter;
-
- // Fix IE's bug.
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
- drupal_add_link(array(
- 'rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => "http://s7.addthis.com/static/r07/widget02.css",
- ));
+function addthis_add_default_js() {
+ // Check if we've done this already.
+ static $addthis_counter = 0;
+ if ($addthis_counter++ > 0) {
+ return $addthis_counter;
}
- if (variable_get('addthis_dropdown_disabled', '0')) {
- $button = sprintf('
- <a class="addthis-button" href="http://www.addthis.com/bookmark.php"
- onclick="addthis_url = location.href; addthis_title = document.title; return addthis_click(this);">
- <img src="%s" width="%d" height="%d" alt="%s" class="%s" /></a>',
- $_SERVER['HTTPS'] == 'on' ? addslashes(check_plain(variable_get('addthis_image_secure', 'https://secure.addthis.com/button1-share.gif'))) : addslashes(check_plain(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'))),
- variable_get('addthis_image_width', '125'),
- variable_get('addthis_image_height', '16'),
- trim(check_plain(strip_tags(variable_get('addthis_image_attributes_alt', 'share')))),
- trim(check_plain(strip_tags(variable_get('addthis_image_attributes_class', 'addthisimage'))))
- );
+ // get the base configuration settings array.
+ $settings = variable_get('addthis_config', array());
+
+ // determine the current language context and add it $settings.
+ global $language;
+ $settings['ui_language'] = $language->language;
+
+ // sanitize the js settings for output.
+ _addthis_check_plain($settings);
+
+ // add the settings array to the page and process it for the AddThis script.
+ $settings = array('addthis' => array('config_default' => $settings));
+ drupal_add_js($settings, 'setting');
+ drupal_add_js('addthis_config = Drupal.settings.addthis.config_default', 'inline');
+
+ $source = _addthis_cache('http://s7.addthis.com/js/250/addthis_widget.js');
+ drupal_add_js($source);
+
+ return $addthis_counter;
+}
+
+/**
+ * Helper function to recursively run an entire array through check_plain().
+ */
+function _addthis_check_plain(&$item) {
+ if (is_array($item)) {
+ foreach($item AS $key => $value) {
+ _addthis_check_plain($value);
+ }
}
else {
- $button = sprintf('
- <a class="addthis-button" href="http://www.addthis.com/bookmark.php"
- onmouseover="return addthis_open(this, \'\', \'%s\', \'%s\')"
- onmouseout="addthis_close()"
- onclick="return addthis_sendto()"><img src="%s" width="%d" height="%d" alt="%s" class="%s" /></a>',
- $teaser ? url('node/'. $node->nid, array('absolute' => 1) ) : '[URL]',
- $teaser ? addslashes($node->title) : '[TITLE]',
- $_SERVER['HTTPS'] == 'on' ? addslashes(check_plain(variable_get('addthis_image_secure', 'https://secure.addthis.com/button1-share.gif'))) : addslashes(check_plain(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'))),
- variable_get('addthis_image_width', '125'),
- variable_get('addthis_image_height', '16'),
- trim(check_plain(strip_tags(variable_get('addthis_image_attributes_alt', 'share')))),
- trim(check_plain(strip_tags(variable_get('addthis_image_attributes_class', 'addthisimage'))))
- );
- if ($_addthis_counter == 1) {
- $button .= sprintf('<script type="text/javascript" src="%s/js/%d/addthis_widget.js">',
- $_SERVER['HTTPS'] == 'on' ? 'https://secure.addthis.com' : 'http://s7.addthis.com',
- variable_get('addthis_widget_version', '152')
- );
- $button .= '</script>';
+ $item = check_plain($item);
+ }
+}
+
+/**
+ * Implementation of hook_views_api().
+ */
+function addthis_views_api() {
+ return array(
+ 'api' => 2,
+ 'path' => drupal_get_path('module', 'addthis'),
+ );
+}
+
+
+/**
+ * Implementation of hook_cron().
+ */
+function addthis_cron() {
+ // Delete the js file every day so it gets regenerated again
+ if (time() - variable_get('addthis_last_cache', 0) >= 86400) {
+ // Delete the js file
+ if (file_delete(file_directory_path() .'/addthis/addthis_widget.js'))
+ drupal_set_message(t('AddThis module: File '.file_directory_path().'/addthis/addthis_widget.js was deleted.'));
+ else
+ drupal_set_message(t('AddThis module: Attempt to delete file '.file_directory_path().'/addthis/addthis_widget.js failed.
+ This means that the possible new versions of addthis_widget.js may not be downloaded and used.'));
+ // Clear aggregated JS files.
+ if (variable_get('preprocess_js', 0)) {
+ drupal_clear_js_cache();
}
+
+ variable_set('addthis_last_cache', time());
}
- return $button;
}
+
+/**
+ * If js file doesn't exist download and cache the .js file locally.
+ * @param $location
+ * The full URL to the external javascript file.
+ * @return mixed
+ * The path to the local javascript file on success, boolean FALSE on failure.
+ */
+function _addthis_cache($location) {
+ // get files directory
+ $directory = file_directory_path() .'/addthis';
+ $file_destination = $directory .'/'. basename($location);
+ // if addthis_cron has deleted addthis js-file, fetch new js file from $location
+ if (!file_exists($file_destination)) {
+ $result = drupal_http_request($location);
+ if ($result->code == 200) {
+ // Check that the files directory is writable
+ if (file_check_directory($directory, FILE_CREATE_DIRECTORY)) {
+ return file_save_data($result->data, $directory .'/'. basename($location), FILE_EXISTS_REPLACE);
+ }
+ }
+ }
+ // if addthis_cron has not deleted js-file use the js-file
+ else {
+ return $file_destination;
+ }
+} \ No newline at end of file
diff --git a/addthis.views.inc b/addthis.views.inc
index 9cb8ef1..646521d 100644
--- a/addthis.views.inc
+++ b/addthis.views.inc
@@ -1,5 +1,6 @@
<?php
// $Id$
+
/**
* @file
* Provide views data and handlers for addthis.module
@@ -10,14 +11,20 @@
*/
function addthis_views_data() {
// We're registering the 'custom_teasers' table.
- $data['node']['addthis'] = array(
- 'title' => t('AddThis'),
- 'help' => t('An <a href="http://www.addthis.com/">AddThis</a> button.'),
+ $data['node']['addthis_button'] = array(
+ 'title' => t('AddThis button'),
+ 'help' => t('An AddThis button, associated with this node.'),
'field' => array(
- 'handler' => 'addthis_handler_field_service_links',
+ 'handler' => 'addthis_handler_field_button',
+ ),
+ );
+ $data['node']['addthis_toolbox'] = array(
+ 'title' => t('AddThis toolbox'),
+ 'help' => t('An AddThis toolbox, associated with this node.'),
+ 'field' => array(
+ 'handler' => 'addthis_handler_field_toolbox',
),
);
-
return $data;
}
@@ -30,8 +37,13 @@ function addthis_views_handlers() {
'path' => drupal_get_path('module', 'addthis'),
),
'handlers' => array(
- 'addthis_handler_field_service_links' => array(
+ 'addthis_handler_field_button' => array(
+ 'parent' => 'views_handler_field',
+ 'file' => 'addthis_handler_field.inc',
+ ),
+ 'addthis_handler_field_toolbox' => array(
'parent' => 'views_handler_field',
+ 'file' => 'addthis_handler_field.inc',
),
),
);
diff --git a/addthis_handler_field.inc b/addthis_handler_field.inc
new file mode 100755
index 0000000..e11b021
--- /dev/null
+++ b/addthis_handler_field.inc
@@ -0,0 +1,83 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * A handler to provide an AddThis button for a particular node.
+ *
+ * @ingroup views_field_handlers
+ */
+class addthis_handler_field_button extends views_handler_field {
+ function construct() {
+ parent::construct();
+ $this->additional_fields['nid'] = 'nid';
+ $this->additional_fields['title'] = 'title';
+ }
+
+ function query() {
+ $this->ensure_my_table();
+ $this->add_additional_fields();
+ }
+
+ function option_definition() {
+ $options = parent::option_definition();
+
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ parent::options_form($form, $form_state);
+
+ // Remove the alteration stuff
+ unset($form['alter']);
+ }
+
+ function render($values) {
+ $nid = $values->{$this->aliases['nid']};
+ $title = $values->{$this->aliases['title']};
+ return theme('addthis_button', NULL, array(
+ 'url' => url('node/' . $nid, array('absolute' => TRUE)),
+ 'title' => check_plain($title),
+ ));
+ }
+}
+
+/**
+ * A handler to provide an AddThis toolbox for a particular node.
+ *
+ * @ingroup views_field_handlers
+ */
+class addthis_handler_field_toolbox extends views_handler_field {
+ function construct() {
+ parent::construct();
+ $this->additional_fields['nid'] = 'nid';
+ $this->additional_fields['title'] = 'title';
+ }
+
+ function query() {
+ $this->ensure_my_table();
+ $this->add_additional_fields();
+ }
+
+ function option_definition() {
+ $options = parent::option_definition();
+
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ parent::options_form($form, $form_state);
+
+ // Remove the alteration stuff
+ unset($form['alter']);
+ }
+
+ function render($values) {
+ $nid = $values->{$this->aliases['nid']};
+ $title = $values->{$this->aliases['title']};
+ return theme('addthis_toolbox', NULL, array(
+ 'url' => url('node/' . $nid, array('absolute' => TRUE)),
+ 'title' => check_plain($title),
+ ));
+ }
+}
diff --git a/addthis_handler_field_service_links.inc b/addthis_handler_field_service_links.inc
deleted file mode 100644
index 2c2a57b..0000000
--- a/addthis_handler_field_service_links.inc
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-// $Id$
-
-/**
- * @file
- * A handler to provide an AddThis field for a particular node.
- *
- * @ingroup views_field_handlers
- */
-class addthis_handler_field_service_links extends views_handler_field {
- function construct() {
- parent::construct();
- $this->additional_fields['nid'] = 'nid';
- $this->additional_fields['title'] = 'title';
- }
-
- function query() {
- $this->ensure_my_table();
- $this->add_additional_fields();
- }
-
- function option_definition() {
- $options = parent::option_definition();
-
- return $options;
- }
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
-
- // Remove the alteration stuff
- unset($form['alter']);
- }
-
- function render($values) {
- if (user_access('view addthis')) {
- $node = new stdClass();
- $node->nid = $values->{$this->aliases['nid']};
- $node->title = $values->{$this->aliases['title']};
- return _addthis_create_button($node, TRUE);
- }
- }
-} \ No newline at end of file
diff --git a/at_cck_field/at_cck_field.info b/at_cck_field/at_cck_field.info
new file mode 100644
index 0000000..666faa2
--- /dev/null
+++ b/at_cck_field/at_cck_field.info
@@ -0,0 +1,6 @@
+; $Id$
+name = Addthis CCK Field
+description = Defines AddThis CCK Field
+dependencies[] = addthis
+package = "AddThis"
+core = 6.x \ No newline at end of file
diff --git a/at_cck_field/at_cck_field.install b/at_cck_field/at_cck_field.install
new file mode 100644
index 0000000..32ed8a9
--- /dev/null
+++ b/at_cck_field/at_cck_field.install
@@ -0,0 +1,40 @@
+<?php
+// $Id$
+// Notify CCK when this module is enabled, disabled, installed, and uninstalled
+// so CCK can do any necessary preparation or cleanup.
+/**
+ * @file
+ * Implementation of hook_install().
+ */
+function at_cck_field_install() {
+ drupal_load('module', 'content');
+ content_notify('install', 'at_cck_field');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function at_cck_field_uninstall() {
+ drupal_load('module', 'content');
+ content_notify('uninstall', 'at_cck_field');
+}
+
+/**
+ * Implementation of hook_enable().
+ *
+ * Notify content module when this module is enabled.
+ */
+function at_cck_field_enable() {
+ drupal_load('module', 'content');
+ content_notify('enable', 'at_cck_field');
+}
+
+/**
+ * Implementation of hook_disable().
+ *
+ * Notify content module when this module is disabled.
+ */
+function at_cck_field_disable() {
+ drupal_load('module', 'content');
+ content_notify('disable', 'at_cck_field');
+}
diff --git a/at_cck_field/at_cck_field.module b/at_cck_field/at_cck_field.module
new file mode 100644
index 0000000..085c115
--- /dev/null
+++ b/at_cck_field/at_cck_field.module
@@ -0,0 +1,441 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * An at_cck_field to define a simple field, widget, and formatter.
+ * A module could define only a field, only a widget, only a
+ * formatter, or any combination. Widgets and formatters must
+ * declare what kind of field they work with, which can be any
+ * existing field as well as any new field the module creates.
+ */
+
+//==========================================//
+// DEFINING A FIELD
+//==========================================//
+
+/**
+ * Implementation of hook_field_info().
+ */
+function at_cck_field_field_info() {
+ return array(
+ // The machine name of the field,
+ // no more than 32 characters.
+ 'at_cck_field' => array(
+ // The human-readable label of the field that will be
+ // seen in the Manage fields screen.
+ 'label' => t('at_cck_field field'),
+ // A description of what type of data the field stores.
+ 'description' => t('Store text data in the database.'),
+ // An icon to use in Panels.
+ 'content_icon' => 'icon_content_text.png',
+ ),
+ );
+}
+
+/**
+ * Implementation of hook_field_settings().
+ */
+function at_cck_field_field_settings($op, $field) {
+ switch ($op) {
+ // Create the form element to be used on the field
+ // settings form. Field settings will be the same for
+ // all shared instances of the same field and should
+ // define the way the value will be stored
+ // in the database.
+ //
+ // tämä vaikuttaa siis kaikkiin mahdollisesti eri content typeihin liitettyihin kenttiin
+ case 'form':
+ $form = array();
+ $form['max_length'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Maximum length'),
+ '#default_value' => is_numeric($field['max_length']) ? $field['max_length'] : 255,
+ '#required' => FALSE,
+
+ // Use #element_validate to validate the settings.
+ '#element_validate' => array('_at_cck_field_length_validate'),
+ '#description' => t('The maximum length of the field in characters. Must be a number between 1 and 255'),
+ );
+ return $form;
+
+ // Return an array of the names of the field settings
+ // defined by this module. These are the items that
+ // CCK will store in the field definition
+ // and they will be available in the $field array.
+ // This should match the items defined in 'form' above.
+ case 'save':
+ return array('max_length');
+
+ // Define the database storage for this field using
+ // the same construct used by schema API. Most fields
+ // have only one column, but there can be any number
+ // of different columns. After the schema API values,
+ // add two optional values to each column,
+ // 'views', to define a Views field
+ // 'sortable', to add a Views sort field
+ //
+ // tämä on itse tallennettava arvo, eli tallennetaan tällä hetkellä merkkijonona
+ case 'database columns':
+ $columns['value'] = array(
+ 'type' => 'varchar',
+ 'length' => is_numeric($field['max_length']) ? $field['max_length'] : 255,
+ 'not null' => FALSE,
+ 'sortable' => TRUE,
+ 'views' => TRUE,
+ );
+ return $columns;
+
+ // Optional: Make changes to the default $data array
+ // created for Views. Omit this if no changes are
+ // needed, use it to add a custom handler or make
+ // other changes.
+ case 'views data':
+ // Start with the $data created by CCK
+ // and alter it as needed. The following
+ // code illustrates how you would retrieve
+ // the necessary data.
+ $data = content_views_field_views_data($field);
+ $db_info = content_database_info($field);
+ $table_alias = content_views_tablename($field);
+ $field_data = $data[$table_alias][$field['field_name'] .'_value'];
+ // Make changes to $data as needed here.
+ return $data;
+ }
+}
+
+/**
+ * Custom validation of settings values.
+ *
+ * Create callbacks like this to do settings validation.
+ */
+function _at_cck_field_length_validate($element, &$form_state) {
+ $value = $form_state['values']['max_length'];
+ if ($value && !is_numeric($value)|| $value < 1 || $value > 255) {
+ form_set_error('max_length', t('"Max length" must be a number between 1 and 255.'));
+ }
+}
+
+/**
+ * Implementation of hook_field().
+ */
+function at_cck_field_field($op, &$node, $field, &$items, $teaser, $page) {
+ switch ($op) {
+ // Do validation on the field values here. The widget
+ // will do its own validation and you cannot make any
+ // assumptions about what kind of widget has been used,
+ // so don't validate widget values, only field values.
+ case 'validate':
+ if (is_array($items)) {
+ foreach ($items as $delta => $item) {
+ // The error_element is needed so that CCK can
+ // set an error on the right sub-element when
+ // fields are deeply nested in the form.
+ $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
+ if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
+ if (!empty($item['value'])) {
+ if (!empty($field['max_length']) && drupal_strlen($item['value']) > $field['max_length']) {
+ form_set_error($error_element, t('%name: the value may not be longer than %max characters.', array('%name' => $field['widget']['label'], '%max' => $field['max_length'])));
+ }
+ }
+ }
+ }
+ return $items;
+
+ // This is where you make sure that user-provided
+ // data is sanitized before being displayed.
+ case 'sanitize':
+ foreach ($items as $delta => $item) {
+ $at_cck_field = check_plain($item['value']);
+ $items[$delta]['safe'] = $at_cck_field;
+ }
+ }
+}
+
+/**
+ * Implementation of hook_content_is_empty().
+ *
+ * CCK has no way to know if something like a zero is
+ * an empty value or a valid value, so return
+ * TRUE or FALSE to a populated field $item array.
+ * CCK uses this to remove empty multi-value elements
+ * from forms.
+ */
+function at_cck_field_content_is_empty($item, $field) {
+ if (empty($item['value'])) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * Implementation of hook content_generate().
+ *
+ * Optional, provide dummy value for nodes created
+ * by the Devel Generate module.
+ */
+function at_cck_field_content_generate($node, $field) {
+ $node_field = array();
+ // Generate a value that respects max_length.
+ if (empty($field['max_length'])) {
+ $field['max_length'] = 12;
+ }
+ $node_field['value'] = user_password($field['max_length']);
+ return $node_field;
+}
+
+/**
+ * Implementation of hook_token_list()
+ * and hook_token_values().
+ *
+ * Optional, provide token values for this field.
+ */
+function at_cck_field_token_list($type = 'all') {
+ if ($type == 'field' || $type == 'all') {
+ $tokens = array();
+
+ $tokens['at_cck_field']['raw'] = t('Raw, unfiltered text');
+ $tokens['at_cck_field']['formatted'] = t('Formatted and filtered text');
+
+ return $tokens;
+ }
+}
+
+function at_cck_field_token_values($type, $object = NULL) {
+ if ($type == 'field') {
+ $item = $object[0];
+
+ $tokens['raw'] = $item['value'];
+ $tokens['formatted'] = isset($item['view']) ? $item['view'] : '';
+ return $tokens;
+ }
+}
+
+//==========================================//
+// DEFINING A FORMATTER
+//==========================================//
+
+/**
+ * Implementation of hook_theme().
+ */
+function at_cck_field_theme() {
+ return array(
+ // Themes for the formatters.
+ 'at_cck_field_formatter_default' => array(
+ 'arguments' => array('element' => NULL),
+ ),
+ 'at_cck_field_formatter_plain' => array(
+ 'arguments' => array('element' => NULL),
+ ),
+ );
+}
+
+/**
+ * Implementation of hook_field_formatter_info().
+ *
+ * All fields should have a 'default' formatter.
+ * Any number of other formatters can be defined as well.
+ * It's nice for there always to be a 'plain' option
+ * for the raw value, but that is not required.
+ *
+ */
+function at_cck_field_field_formatter_info() {
+ return array(
+ // The machine name of the formatter.
+ 'default' => array(
+ // The human-readable label shown on the Display
+ // fields screen.
+ 'label' => t('Default'),
+ // An array of the field types this formatter
+ // can be used on.
+ 'field types' => array('at_cck_field'),
+ // CONTENT_HANDLE_CORE: CCK will pass the formatter
+ // a single value.
+ // CONTENT_HANDLE_MODULE: CCK will pass the formatter
+ // an array of all the values. None of CCK's core
+ // formatters use multiple values, that is an option
+ // available to other modules that want it.
+ 'multiple values' => CONTENT_HANDLE_CORE,
+ ),
+ 'plain' => array(
+ 'label' => t('Plain text'),
+ 'field types' => array('at_cck_field'),
+ 'multiple values' => CONTENT_HANDLE_CORE,
+ ),
+ );
+}
+
+/**
+ * Theme function for 'default' at_cck_field field formatter.
+ *
+ * $element['#item']: the sanitized $delta value for the item,
+ * $element['#field_name']: the field name,
+ * $element['#type_name']: the $node->type,
+ * $element['#formatter']: the $formatter_name,
+ * $element'#node']: the $node,
+ * $element['#delta']: the delta of this item, like '0',
+ *
+ */
+function theme_at_cck_field_formatter_default($element) {
+
+ $addthis_widget_type = variable_get('addthis_widget_type', 'addthis_button');
+ if (addthis_show_addthis('node', $element['#node'], $teaser = FALSE)) {
+ if($element['#item']['value'] == 'default')
+ return theme($addthis_widget_type); //theme_addthis_button();
+ }
+ //$element['#item']['safe'];
+}
+
+/**
+ * Theme function for 'plain' at_cck_field field formatter.
+ */
+function theme_at_cck_field_formatter_plain($element) {
+ //drupal_set_message(dsm($element));
+ $addthis_widget_type = variable_get('addthis_widget_type', 'addthis_button');
+ if (addthis_show_addthis('node', $element['#node'], $teaser = FALSE)) {
+ if($element['#item']['value'] == 'default')
+ return theme($addthis_widget_type); //theme_addthis_button();
+ }
+ //strip_tags($element['#item']['safe']);
+}
+
+//==========================================//
+// DEFINING A WIDGET
+//==========================================//
+
+/**
+ * Implementation of hook_widget_info().
+ *
+ * Here we indicate that the content module will handle
+ * the default value and multiple values for these widgets.
+ *
+ * Callbacks can be omitted if default handing is used.
+ * They're included here just so this module can be used
+ * as an at_cck_field for custom modules that might do things
+ * differently.
+ */
+function at_cck_field_widget_info() {
+ return array(
+ // The machine name of the widget, no more than 32
+ // characters.
+ 'at_cck_field_widget' => array(
+ // The human-readable label of the field that will be
+ // seen in the Manage fields screen.
+ 'label' => t('addthis widget'),
+ // An array of the field types this widget can be
+ // used with.
+ 'field types' => array('at_cck_field'),
+ // Who will handle multiple values, default is core.
+ // 'CONTENT_HANDLE_MODULE' means the module does it.
+ // See optionwidgets for an at_cck_field of a module that
+ // handles its own multiple values.
+ 'multiple values' => CONTENT_HANDLE_CORE,
+ 'callbacks' => array(
+ // Who will create the default value, default is core.
+ // 'CONTENT_CALLBACK_CUSTOM' means the module does it.
+ // 'CONTENT_CALLBACK_NONE' means this widget has
+ // no default value.
+ 'default value' => CONTENT_CALLBACK_DEFAULT,
+ ),
+ ),
+ );
+}
+
+/**
+ * Implementation of hook_widget_settings().
+ */
+function at_cck_field_widget_settings($op, $widget) {
+ switch ($op) {
+ // Create the form element to be used on the widget
+ // settings form. Widget settings can be different
+ // for each shared instance of the same field and
+ // should define the way the value is displayed to
+ // the user in the edit form for that content type.
+ case 'form':
+ $form = array();
+ $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
+ $form['size'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Size of textfield'),
+ '#default_value' => $size,
+ '#element_validate' => array('_element_validate_integer_positive'),
+ '#required' => TRUE,
+ );
+ return $form;
+
+ // Return an array of the names of the widget settings
+ // defined by this module. These are the items that
+ // CCK will store in the widget definition and they
+ // will be available in the $field['widget'] array.
+ // This should match the items defined in 'form' above.
+ case 'save':
+ return array('size');
+ }
+}
+
+/**
+ * Implementation of hook_widget().
+ *
+ * Attach a single form element to the form.
+ *
+ * CCK core fields only add a stub element and builds
+ * the complete item in #process so reusable elements
+ * created by hook_elements can be plugged into any
+ * module that provides valid $field information.
+ *
+ * Custom widgets that don't care about using hook_elements
+ * can be built out completely at this time.
+ *
+ * If there are multiple values for this field and CCK is
+ * handling multiple values, the content module will call
+ * this function as many times as needed.
+ *
+ * @param $form
+ * the entire form array,
+ * $form['#node'] holds node information
+ * @param $form_state
+ * the form_state,
+ * $form_state['values'][$field['field_name']]
+ * holds the field's form values.
+ * @param $field
+ * the field array
+ * @param $items
+ * array of default values for this field
+ * @param $delta
+ * the order of this item in the array of
+ * subelements (0, 1, 2, etc)
+ *
+ * @return
+ * the form item for a single element for this field
+ */
+function at_cck_field_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+
+ $options = array(
+ 'default' => t('default'),
+ 'custom' => t('custom'));
+
+ // miten arvo valitaan. Huomaa, että value täsmää tauluun tallennettavan kentän nimeä
+ $element['value'] = array(
+ '#type' => 'select',
+ '#title' => check_plain($field['widget']['label']),
+ '#description' => check_plain($field['widget']['description']),
+ '#options' => $options,
+ '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
+ '#autocomplete_path' => $element['#autocomplete_path'],
+ //'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
+ '#attributes' => array('class' => 'at_cck_field'),
+ //'#maxlength' => !empty($field['max_length']) ? $field['max_length'] : NULL,
+ );
+
+ // Used so that hook_field('validate') knows where to
+ // flag an error in deeply nested forms.
+ if (empty($form['#parents'])) {
+ $form['#parents'] = array();
+ }
+ $element['_error_element'] = array(
+ '#type' => 'value',
+ '#value' => implode('][', array_merge($form['#parents'], array('value'))),
+ );
+
+ return $element;
+} \ No newline at end of file
diff --git a/at_content_type/at_content_type.info b/at_content_type/at_content_type.info
new file mode 100644
index 0000000..9aaf18e
--- /dev/null
+++ b/at_content_type/at_content_type.info
@@ -0,0 +1,8 @@
+; $Id$
+name = AddThis Content Type
+description = Provides content type based visibility restrictions for the AddThis module
+core = 6.x
+
+package = "AddThis"
+dependencies[] = addthis
+version = "6.x-0.1-dev" \ No newline at end of file
diff --git a/at_content_type/at_content_type.module b/at_content_type/at_content_type.module
new file mode 100644
index 0000000..1f6ec01
--- /dev/null
+++ b/at_content_type/at_content_type.module
@@ -0,0 +1,79 @@
+<?php
+// $Id$
+/**
+* @file
+* A Test Module.
+*/
+
+/*******************************************************************************
+* Hook Functions (Drupal)
+******************************************************************************/
+
+/**
+* Display help and module information
+* @param path which path of the site we're displaying help
+* @param arg array that holds the current path as would be returned from arg() function
+* @return help text for the path
+*/
+function at_content_type_help($path, $arg) {
+ switch ($path) {
+ case "admin/help/at_content_type":
+ $output = '<p>'. t("at_content_type requires addthis module to function. at_content_type makes
+ it possible to allow or disallow of showing addthis links based on nodes based on content types.") .'</p>';
+ break;
+ }
+ return $output;
+}
+
+/**
+* Valid permissions for this module
+* @return array An array of valid permissions for the at_content_type module
+*/
+function at_content_type_perm() {
+ return array('administer at_content_type');
+}
+
+
+/**
+* Implementing custom hook that addthis module invokes
+*
+* @param $node
+* noe being processed
+*
+* @return
+* TRUE if the content type of node being processed belongs to the nodetype list
+*/
+function at_content_type_restrict($node) {
+
+ // if node's type exists in the node types associated with addthis links return true otherwise return false
+
+ $node_types = variable_get('addthis_node_types', array());
+ if ($node_types[$node->type] === $node->type)
+ return TRUE;
+
+ return FALSE;
+}
+
+/**
+ * Implementation of hook_form_alter().
+ *
+ * Modify node form to have checkbox to allow/disallow displaying
+ * of addthis links with certain node
+ */
+function at_content_type_form_alter(&$form, $form_state, $form_id) {
+ // Normally a switch is used because you may want to alter more than
+ // one form and it is easy to add a new case for each form.
+
+ switch ($form_id) {
+ case 'addthis_visibility_config_form':
+ $form['addthis_visibility']['addthis_node_types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('AddThis content types'),
+ '#description' => t('Select the node types on which to show/hide AddThis links.'),
+ '#options' => node_get_types('names'),
+ '#default_value' => variable_get('addthis_node_types', array()),
+ );
+ break;
+ }
+}
+
diff --git a/at_export/at_export.info b/at_export/at_export.info
new file mode 100644
index 0000000..2681b35
--- /dev/null
+++ b/at_export/at_export.info
@@ -0,0 +1,6 @@
+; $Id$
+name = AddThis Export
+description = Enables exportting of AddThis settings in order to use different settings variants
+dependencies[] = addthis
+package = "AddThis"
+core = 6.x \ No newline at end of file
diff --git a/at_export/at_export.module b/at_export/at_export.module
new file mode 100644
index 0000000..c5d3f16
--- /dev/null
+++ b/at_export/at_export.module
@@ -0,0 +1,44 @@
+<?php
+
+function at_export_menu() {
+
+ $items = array();
+ $items['admin/settings/addthis/export'] = array(
+ 'title' => 'Export AddThis widget settings',
+ 'type' => MENU_LOCAL_TASK,
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('at_export_widget_export_form'),
+ 'access arguments' => array('administer addthis'),
+ //'file' => 'addthis.admin.inc',
+ );
+
+ return $items;
+}
+
+function at_export_widget_export_form() {
+ // Drupal visibility settings for AddThis.
+ $form['addthis_export'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Export AddThis widget settings'),
+ '#description' => t('Export AddThis widget settings for multiple variants of AddThis'),
+ );
+
+ $form['addthis_export']['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name the settings to be imported'),
+ '#description' => t('Name identifies the settings'),
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Export'),
+ '#size' => 20,
+ );
+
+ return $form;
+}
+
+
+function at_export_widget_export_form_submit() {
+
+ drupal_set_message('Submit function called');
+} \ No newline at end of file
diff --git a/at_taxonomy/at_taxonomy.info b/at_taxonomy/at_taxonomy.info
new file mode 100644
index 0000000..7f4997a
--- /dev/null
+++ b/at_taxonomy/at_taxonomy.info
@@ -0,0 +1,6 @@
+; $Id$
+name = AddThis Taxonomy
+description = Provides taxonomy term based visibility restrictions for the AddThis module
+dependencies[] = addthis
+package = "AddThis"
+core = 6.x \ No newline at end of file
diff --git a/at_taxonomy/at_taxonomy.module b/at_taxonomy/at_taxonomy.module
new file mode 100644
index 0000000..3439119
--- /dev/null
+++ b/at_taxonomy/at_taxonomy.module
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * Implementation of form_alter
+ *
+ * Function adds taxonomy term related options to the visibility form of addthis
+ * module.
+ *
+ */
+function at_taxonomy_form_alter(&$form, $form_state, $form_id) {
+
+ switch ($form_id) {
+ case 'addthis_visibility_config_form':
+ $options= _get_taxonomy_terms();
+
+ $form['addthis_visibility']['addthis_taxonomy_terms'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Taxonomy terms'),
+ '#description' => t('Show/hide addthis links on nodes categorized by the following taxonomy terms.'),
+ '#options' => $options,
+ '#default_value' => variable_get('addthis_taxonomy_terms', array()),
+ );
+ break;
+ }
+}
+
+/**
+* Implementing custom hook that addthis module invokes.
+*
+* @param $node
+* node being processed
+*
+* @return
+* TRUE if the node being processed has taxonomy terms that belong to term list
+*/
+function at_taxonomy_restrict($node){
+
+ $belongs_to_term_list = FALSE;
+
+ $tids = variable_get('addthis_taxonomy_terms', array());
+
+ $query = "SELECT tid FROM {term_node} WHERE nid = %d";
+ $result = db_query($query, $node->nid);
+ /*
+ instead of making a new database query, one could use here also
+ foreach ($node['taxonomy'] as $value){
+ if (in_array($value->tid, $tids)) ...
+ }
+ */
+
+ if ($result) {
+ while ($row = db_fetch_array($result)) {
+ if (in_array($row['tid'], $tids)) {
+ $belongs_to_term_list = TRUE;
+ break;
+ }
+ }
+ }
+
+ return $belongs_to_term_list;
+}
+
+/**
+* returns an associative array. This is use to present all the terms as options in the term list
+* in the admin form
+*
+* @return
+* associative array of taxonomy terms for the admin form
+*/
+function _get_taxonomy_terms() {
+
+ $termlist = array();
+ $query = "SELECT tid, name from {term_data}";
+ $result = db_query($query);
+ if ($result) {
+ while ($row = db_fetch_array($result)) {
+ $termlist[$row['tid']] = $row['name'];
+ }
+ }
+ return $termlist;
+} \ No newline at end of file
diff --git a/at_visibility/at_visibility.info b/at_visibility/at_visibility.info
new file mode 100755
index 0000000..6dbe604
--- /dev/null
+++ b/at_visibility/at_visibility.info
@@ -0,0 +1,8 @@
+; $Id$
+name = AddThis Visibility
+description = Provides node based visibility restrictions for the AddThis module
+core = 6.x
+
+package = "AddThis"
+dependencies[] = addthis
+version = "6.x-0.1-dev" \ No newline at end of file
diff --git a/at_visibility/at_visibility.install b/at_visibility/at_visibility.install
new file mode 100755
index 0000000..958aefa
--- /dev/null
+++ b/at_visibility/at_visibility.install
@@ -0,0 +1,36 @@
+<?php
+// $Id$
+
+/**
+* Implementation of hook_install()
+*/
+function at_visibility_install() {
+ drupal_install_schema('at_visibility');
+ db_query("DELETE FROM {cache}");
+}
+
+/**
+* Implementation of hook_uninstall()
+*/
+function at_visibility_uninstall() {
+ drupal_uninstall_schema('at_visibility');
+}
+
+/**
+* Implementation of hook_schema()
+* @return array of Schema API table definitions.
+*/
+function at_visibility_schema() {
+ $schema['at_visibility_nodelist'] = array(
+ 'fields' => array(
+ 'id' => array('type' => 'serial', 'size' => 'big', 'unsigned' => TRUE, 'not null' => TRUE,
+ 'description'=> "id"),
+
+ 'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0,
+ 'description'=> "Node id. These nodes will show/not show addthis links"),
+ ),
+ 'primary key' => array('id') //Don't put a comma after primary key definition, since doing so will cause database errors.
+ );
+
+ return $schema;
+} \ No newline at end of file
diff --git a/at_visibility/at_visibility.module b/at_visibility/at_visibility.module
new file mode 100755
index 0000000..bb2d889
--- /dev/null
+++ b/at_visibility/at_visibility.module
@@ -0,0 +1,213 @@
+<?php
+// $Id$
+/**
+* @file
+* A Test Module.
+*/
+
+/*******************************************************************************
+* Hook Functions (Drupal)
+******************************************************************************/
+
+/**
+* Display help and module information
+* @param path which path of the site we're displaying help
+* @param arg array that holds the current path as would be returned from arg() function
+* @return help text for the path
+*/
+function at_visibility_help($path, $arg) {
+ switch ($path) {
+ case "admin/help/at_visibility":
+ $output = '<p>'. t("at_visibility requires addthis module to function. at_visibility makes
+ it possible to allow or disallow of showing addthis links on individual nodes.") .'</p>';
+ break;
+ }
+ return $output;
+}
+
+/**
+* Valid permissions for this module
+* @return array An array of valid permissions for the at_visibility module
+*/
+function at_visibility_perm() {
+ return array('administer at_visibility');
+}
+
+/**
+ * Implementation of hook_nodeapi
+ *
+ * This is needed to handle additional data of the node.
+ * Additional data is information whether the node being processed
+ * belongs to the node list which can be used as a basis to allow or disallow
+ * display of addthis links
+ *
+ * @param <type> $node
+ * @param <type> $op
+ * @param <type> $a3
+ * @param <type> $a4
+ */
+function at_visibility_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+ // Run $op == load for any user.
+ if ($op == 'load') {
+ $result = db_query('SELECT * FROM {at_visibility_nodelist} WHERE nid = %d', $node->nid);
+ $row = db_fetch_array($result);
+ if (isset($row['nid'])) {
+ $node->in_list = TRUE;
+
+ }
+ else {
+ $node->in_list = FALSE;
+ }
+ }
+ elseif (1) {
+ switch ($op) {
+ case 'view':
+ if (isset($a4) && $a4 && isset($node->unpublish_on) && $node->unpublish_on) {
+ $unavailable_after = date("d-M-Y H:i:s T", $node->unpublish_on);
+ drupal_set_html_head('<meta name="googlebot" content="unavailable_after: '. $unavailable_after .'" />');
+ }
+ break;
+ case 'validate':
+
+ case 'presave':
+
+
+ break;
+
+ case 'insert':
+ // only insert into database if we need to (un)publish this node at some date
+ if (isset($node->nid) && $node->nid && (isset($node->in_list) && $node->in_list != NULL) ) {
+ db_query('INSERT INTO {at_visibility_nodelist} (nid) VALUES (%d)', $node->nid);
+ }
+ break;
+
+ case 'update':
+
+ if (isset($node->nid) && $node->nid) {
+ $exists = db_result(db_query('SELECT nid FROM {at_visibility_nodelist} WHERE nid = %d', $node->nid));
+
+ // if in_list is set and is not null and nid doesn't exist in the list already, create a record
+ if (isset($node->in_list) && $node->in_list != NULL && $exists === FALSE) {
+ db_query('INSERT INTO {at_visibility_nodelist} (nid) VALUES (%d)', $node->nid);
+ }
+ // if checkbox is unchecked delete record from node list
+ if (isset($node->in_list) && $node->in_list == FALSE) {
+ db_query('DELETE FROM {at_visibility_nodelist} WHERE nid = (%d)', $node->nid);
+ }
+
+ }
+ break;
+ case 'delete':
+ if (isset($node->nid) && $node->nid) {
+ db_query('DELETE FROM {at_visibility_nodelist} WHERE nid = %d', $node->nid);
+ }
+ break;
+ }
+ }
+}
+
+
+/**
+* Implementing custom hook that addthis module invokes
+*
+* @param $nid
+* determine whether addthis links with this nid will be shown
+*
+* @return
+* TRUE if addthis links will be displayed
+*/
+function at_visibility_restrict($node) {
+
+ // if node exists in nodelist return true otherwise return false
+ // !!! TODO
+ // korvaa kyselyllä, get_nodelist hidas
+ //return in_array($node->nid, _at_visibility_get_nodelist());
+ return _in_at_visibility_nodelist($node->nid);
+}
+
+/**
+ * Implementation of hook_form_alter().
+ *
+ * Modify node form to have checkbox to allow/disallow displaying
+ * of addthis links with certain node
+ */
+function at_visibility_form_alter(&$form, $form_state, $form_id) {
+
+ $node = $form['#node'];
+
+ if ($form_id == $node->type.'_node_form') {
+
+ $form['at_visibility']=array(
+ '#title' => t('AddThis visibility'),
+ '#type' => 'fieldset',
+ '#decription' => t('Control whether this node will belong to node list'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+
+ $options=array(
+ 'include' => t('include this node in the nodelist'),
+ );
+
+ $defaults = $node->in_list;
+ $form['at_visibility']['in_list']=array(
+ '#title' => t('inlude node in nodelist'),
+ '#type' => 'checkbox',
+ '#description' => t('Whether this node will display or hide addthis links
+ is determined by the Visibility type -option in <a href="/admin/settings/addthis/visibility"> AddThis settings.</a>'),
+ '#default_value' => $defaults,
+ );
+ }
+
+ if ($form_id == 'addthis_visibility_config_form') {
+
+ $txt = 'Currently following nodes are included in the nodelist: ';
+ $query = 'SELECT {node.title} title
+ FROM {node}, {at_visibility_nodelist}
+ WHERE {node.nid} = {at_visibility_nodelist.nid}';
+ $result = db_query($query);
+
+ $options = array();
+
+ if ($result) {
+ while ($row = db_fetch_array($result)) {
+ $options[$row['title']] = $row['title'];
+ $txt .= $row['title']. ', ';
+
+ }
+ }
+
+ $form['addthis_visibility']['reset_nodelist'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Reset nodelist',
+ '#description' => $txt,
+ );
+
+ $form['#submit'][] = '_at_visibility_submit';
+
+ }
+}
+
+function _at_visibility_submit(&$form, &$form_state) {
+
+ if($form_state['values']['reset_nodelist']) {
+ $query = 'DELETE FROM {at_visibility_nodelist}';
+ if (db_query($query))
+ drupal_set_message(t("Values from nodelist has been deleted"));
+ }
+ // !!! jostain syystä unset ei tässä enää vaikuta..
+ unset($form['addthis_visibility']['reset_nodelist']);
+ // drupal_set_message(dsm($form));
+ // voiko tämä funkkari unsetata ne joita ei haluta tallentaa variables tauluun
+}
+
+function _in_at_visibility_nodelist($nid) {
+
+ $result = db_query("SELECT nid FROM {at_visibility_nodelist} WHERE nid = %d ORDER BY id", $nid);
+ if ($result) {
+ if (db_fetch_array($result) )
+ return TRUE;
+ }
+
+ return FALSE;
+}