array( 'arguments' => array('form' => NULL) ) ); } /******************************************************************************* * Hook Functions (Share) ******************************************************************************/ /** * Implementation of hook_share_info(). */ function link_codes_share_info() { return array( 'tab' => array( 'title' => t('Link codes'), 'enabled' => TRUE, 'weight' => 0, 'module' => 'link_codes', 'settings' => array( 'codes' => array('direct' => 'direct', 'html' => 'html') ) ) ); } /** * Implementation of hook_share_tab(). */ function link_codes_share_tab($op, $args, $node = NULL) { switch ($op) { case 'load': $codes = array(); if ($result = db_result(db_query("SELECT codes FROM {share_link_codes} WHERE share_id = %d", $args->share_id))) { $codes = unserialize($result); } return array('codes' => $codes); case 'settings': $defaults = ($args['codes']) ? array_values($args['codes']) : array('direct', 'html'); $form = array('#theme' => 'link_codes_settings'); $form['codes'] = array( '#type' => 'checkboxes', '#title' => t('Types'), '#description' => t('Provide generated link code(s) that point to the node.'), '#default_value' => array_filter($defaults), '#options' => array('direct' => t('Direct URL'), 'html' => t('HTML code'), 'forum' => t('Forum code')) ); return $form; case 'process': $output = ''; foreach ($args['codes'] as $code) { if ($code) { $output.= link_codes_generate($code, $node); } } return $output; case 'validate': $codes = array_filter($args['tabs']['link_codes']['settings']['codes']); if (empty($codes)) { form_set_error('codes', t('At least one link code type has to be enabled.')); } break; case 'insert': $codes = array_filter($args->tabs['link_codes']['settings']['codes']); db_query("INSERT INTO {share_link_codes} (share_id, codes) VALUES (%d, '%s')", $args->share_id, serialize($codes)); break; case 'update': $codes = array_filter($args->tabs['link_codes']['settings']['codes']); db_query("UPDATE {share_link_codes} SET codes = '%s' WHERE share_id = %d", serialize($codes), $args->share_id); if (db_affected_rows() <= 0) { db_query("INSERT INTO {share_link_codes} (share_id, codes) VALUES (%d, '%s')", $args->share_id, serialize($codes)); } break; case 'delete': db_query("DELETE FROM {share_link_codes} WHERE share_id = %d", $args->share_id); break; } } /******************************************************************************* * Callback Functions, Forms, and Tables ******************************************************************************/ function link_codes_generate($op, $node) { $alias = drupal_get_path_alias('node/'.$node->nid); switch ($op) { case "direct": return ''; case "html": return ''; case "forum": return ''; } } /******************************************************************************* * Module and Helper Functions ******************************************************************************/ function theme_link_codes_settings($form) { drupal_add_css(drupal_get_path('module', 'link_codes') .'/link_codes.css'); return ''; }