diff --git a/tweetbutton.admin.inc b/tweetbutton.admin.inc index 1aa0d63..5d13484 100644 --- a/tweetbutton.admin.inc +++ b/tweetbutton.admin.inc @@ -1,15 +1,16 @@ 'fieldset', '#title' => t('Default settings for tweetbutton'), ); - + $form['button']['tweetbutton_button'] = array( '#type' => 'select', '#options' => array( @@ -20,8 +21,7 @@ function tweetbutton_admin_settings() { '#default_value' => variable_get('tweetbutton_button', 'vertical'), '#id' => 'tweetbutton-button', ); - - + $form['button']['tweetbutton_tweet_text'] = array( '#type' => 'textfield', '#title' => t('Tweet Text'), @@ -32,7 +32,7 @@ function tweetbutton_admin_settings() { $form['button']['tokens'] = array( '#token_types' => array('node'), '#theme' => 'token_tree', - ); + ); $form['button']['tweetbutton_size'] = array( '#title' => t('Tweetbutton size'), @@ -43,14 +43,14 @@ function tweetbutton_admin_settings() { ), '#default_value' => variable_get('tweetbutton_size'), ); - + $form['button']['tweetbutton_hashtags'] = array( '#title' => t('Hashtags'), '#type' => 'textfield', '#default_value' => variable_get('tweetbutton_hashtags'), '#description' => t('Comma separated hashtags to be used in every tweet'), ); - + $form['button']['tweetbutton_language'] = array( '#title' => t('Language'), '#description' => t('This is the language that the button will render in on your website. People will see the Tweet dialog in their selected language for Twitter.com.'), @@ -65,16 +65,15 @@ function tweetbutton_admin_settings() { ), '#default_value' => variable_get('tweetbutton_language'), ); - - if (module_exists('shorten')) { + if (module_exists('shorten')) { $services = array(); $services[0] = t('Use t.co twitter default url shortener'); $all_services = module_invoke_all('shorten_service'); foreach (array_keys($all_services) as $value) { $services[$value] = $value; } - + $form['button']['tweetbutton_shorten_service'] = array( '#title' => t('Shorten service to use to add custom url'), '#type' => 'select', @@ -82,12 +81,12 @@ function tweetbutton_admin_settings() { '#default_value' => variable_get('tweetbutton_shorten_service', 0), ); } - + $form['button']['follow'] = array( '#type' => 'fieldset', '#title' => t('Recommend people to follow'), ); - + $form['button']['follow']['tweetbutton_account'] = array( '#type' => 'textfield', '#title' => t('Twitter account to follow'), @@ -95,39 +94,37 @@ function tweetbutton_admin_settings() { '#default_value' => variable_get('tweetbutton_account'), '#id' => 'tweetbutton-account', ); - + $form['button']['follow']['tweetbutton_rel_account_name'] = array( '#type' => 'textfield', '#title' => t('Related Account'), '#default_value' => variable_get('tweetbutton_rel_account_name'), '#description' => t('This should be site default twitter account'), ); - + $form['button']['follow']['tweetbutton_rel_account_description'] = array( '#type' => 'textfield', '#title' => t('Related Account Description'), '#default_value' => variable_get('tweetbutton_rel_account_description'), ); - - $form['follow_button'] = array( '#type' => 'fieldset', '#title' => t('Follow button settings'), ); - + $form['follow_button']['tweetbutton_follow_show_count'] = array( '#type' => 'checkbox', '#title' => t('Show follow count'), '#default_value' => variable_get('tweetbutton_follow_show_count', TRUE), ); - + $form['follow_button']['tweetbutton_follow_screen_name'] = array( '#type' => 'textfield', '#title' => t('Screen name to follow'), '#default_value' => variable_get('tweetbutton_follow_screen_name'), ); - + $form['follow_button']['tweetbutton_follow_size'] = array( '#title' => t('Tweetbutton size'), '#type' => 'select', @@ -137,6 +134,6 @@ function tweetbutton_admin_settings() { ), '#default_value' => variable_get('tweetbutton_follow_size'), ); - + return system_settings_form($form); -} \ No newline at end of file +} diff --git a/tweetbutton.info b/tweetbutton.info index 491a4b4..a918c40 100644 --- a/tweetbutton.info +++ b/tweetbutton.info @@ -1,5 +1,5 @@ name = Tweetbutton -description = Add tweet button to your website without having to leave the page +description = Add tweet button to your website without having to leave the page core = 7.x dependencies[] = token -configure = admin/config/services/tweetbutton \ No newline at end of file +configure = admin/config/services/tweetbutton diff --git a/tweetbutton.install b/tweetbutton.install index b8dec17..75b2344 100644 --- a/tweetbutton.install +++ b/tweetbutton.install @@ -2,7 +2,7 @@ /** - * Implements hook_field_schema() + * Implements hook_field_schema(). */ function tweetbutton_field_schema($field) { switch ($field['type']) { @@ -15,7 +15,7 @@ function tweetbutton_field_schema($field) { ), 'account' => array( 'type' => 'varchar', - 'length' => 32, + 'length' => 32, 'not null' => FALSE, ), ); @@ -31,7 +31,7 @@ function tweetbutton_field_schema($field) { } /** - * Implementation of hook_uninstall() + * Implements hook_uninstall(). */ function tweetbutton_uninstall() { variable_del('tweetbutton_button'); @@ -43,9 +43,10 @@ function tweetbutton_uninstall() { variable_del('tweetbutton_rel_account_description'); variable_del('tweetbutton_node_weight'); variable_del('tweetbutton_node_types'); - variable_del('tweetbutton_node_location'); + variable_del('tweetbutton_node_location'); variable_del('tweetbutton_shorten_service'); variable_del('tweetbutton_follow_show_count'); variable_del('tweetbutton_follow_screen_name'); variable_del('tweetbutton_follow_size'); -} \ No newline at end of file +} + diff --git a/tweetbutton.module b/tweetbutton.module index 87081d7..7ec1891 100644 --- a/tweetbutton.module +++ b/tweetbutton.module @@ -16,7 +16,7 @@ function tweetbutton_help($path, $arg) { } /** - * Implementation of hook_field_info() + * Implements hook_field_info(). */ function tweetbutton_field_info() { return array( @@ -31,20 +31,20 @@ function tweetbutton_field_info() { } /** - * Implementation of hook_field_is_empty() + * Implements hook_field_is_empty(). */ function tweetbutton_field_is_empty($item, $field) { return FALSE; } /** - * Implementation of hook_field_instance_settings_form + * Implements hook_field_instance_settings_form(). */ function tweetbutton_field_instance_settings_form($field, $instance) { $settings = $instance['settings']; $form = array(); - + $form['tweet_text'] = array( '#type' => 'textfield', '#title' => t('Tweet text'), @@ -58,7 +58,7 @@ function tweetbutton_field_instance_settings_form($field, $instance) { '#default_value' => isset($settings['author_twitter'])? $settings['author_twitter']: variable_get('tweetbutton_account'), '#description' => t('This user will be @mentioned in the suggested'), ); - + if ($instance['entity_type'] == 'taxonomy_term') { $token_type = 'term'; } @@ -70,12 +70,12 @@ function tweetbutton_field_instance_settings_form($field, $instance) { '#token_types' => array($token_type), '#theme' => 'token_tree', ); - + return $form; } /** - * Implementation of hook_field_widget_info() + * Implements hook_field_widget_info(). */ function tweetbutton_field_widget_info() { return array( @@ -91,7 +91,7 @@ function tweetbutton_field_widget_info() { } /** - * Implementation of hook_field_widget_form() + * Implements hook_field_widget_form(). */ function tweetbutton_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { $default_author = isset($instance['settings']['author_twitter'])? $instance['settings']['author_twitter']: ''; @@ -105,7 +105,7 @@ function tweetbutton_field_widget_form(&$form, &$form_state, $field, $instance, '#maxlength' => 128, '#access' => user_access('use tweetbutton field'), ); - + $element['text'] = array( '#type' => 'textfield', '#default_value' => !empty($items[$delta]['text'])? $items[$delta]['text']: $default_text, @@ -114,12 +114,12 @@ function tweetbutton_field_widget_form(&$form, &$form_state, $field, $instance, '#maxlength' => 32, '#access' => user_access('use tweetbutton field'), ); - + return $element; } /** - * Implementation of hook_field_presave() + * Implements hook_field_presave(). */ function tweetbutton_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { if ($field['type'] == 'tweetbutton') { @@ -134,7 +134,7 @@ function tweetbutton_field_presave($entity_type, $entity, $field, $instance, $la /** - * Implementation of hook_field_formatter_info() + * Implements hook_field_formatter_info(). */ function tweetbutton_field_formatter_info() { return array( @@ -168,7 +168,7 @@ function tweetbutton_field_formatter_info() { function tweetbutton_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { $display = $instance['display'][$view_mode]; $settings = $display['settings']; - + $element['size'] = array( '#type' => 'select', '#title' => t('Tweetbutton size'), @@ -213,7 +213,7 @@ function tweetbutton_field_formatter_view($entity_type, $entity, $field, $instan $items[$delta] = array( 'text' => '', 'account' => '' - ); + ); } $uri = entity_uri($entity_type, $entity); @@ -228,14 +228,13 @@ function tweetbutton_field_formatter_view($entity_type, $entity, $field, $instan ), '#entity' => $entity, '#entity_type' => $entity_type, - ); return $element; } /** - * Implementation of hook_menu() - */ + * Implements hook_menu(). + */ function tweetbutton_menu() { $items = array(); @@ -253,7 +252,7 @@ function tweetbutton_menu() { } /** - * Implementation of hook_theme() + * Implements hook_theme(). */ function tweetbutton_theme() { return array( @@ -271,7 +270,7 @@ function tweetbutton_theme() { /** - * Implementation of hook_cron() + * Implements of hook_cron(). */ function tweetbutton_cron() { // @TODO: Fetch count of each page where tweetbutton is on and add it to column 'count' in field @@ -279,12 +278,10 @@ function tweetbutton_cron() { if (!variable_get('tweetbutton_get_count', FALSE)) { return; } - - } /** - * Implementation of hook_permission() + * Implements hook_permission(). */ function tweetbutton_permission() { return array( @@ -301,12 +298,12 @@ function tweetbutton_permission() { } /** - * Implementation of hook_block_info() + * Implements hook_block_info(). */ function tweetbutton_block_info() { $blocks['tweetbutton_tweet'] = array( 'info' => t('Tweetbutton tweet'), - ); + ); $blocks['tweetbutton_follow'] = array( 'info' => t('Tweetbutton follow'), ); @@ -314,13 +311,13 @@ function tweetbutton_block_info() { } /** - * Implementation of hook_block_configure + * Implements hook_block_configure(). */ function tweetbutton_block_view($delta = '') { if ($delta == 'tweetbutton_tweet') { $block['subject'] = t('Tweetbutton tweet'); $block['content'] = theme('tweetbutton_tweet_display'); - return $block; + return $block; } elseif ($delta == 'tweetbutton_follow') { $block['subject'] = t('Tweetbutton follow'); @@ -330,15 +327,16 @@ function tweetbutton_block_view($delta = '') { } /** - * Helper function to build the required tweet attributes + * Helper function to build the required tweet attributes. + * * @param $options * Context specific options - * @return + * @return * List of attributes to be rendered for twitter tweetbutton */ function tweetbutton_tweet_get_attributes($options = array()) { global $language; - + $default_option = array( 'type' => variable_get('tweetbutton_button', 'vertical'), 'tweet_text' => variable_get('tweetbutton_tweet_text'), @@ -348,15 +346,15 @@ function tweetbutton_tweet_get_attributes($options = array()) { 'rel_desc' => variable_get('tweetbutton_rel_account_description'), 'size' => variable_get('tweetbutton_size', 'medium') ); - + if (empty($options['url'])) { - $options['url'] = url($_GET['q'], array('absolute' => TRUE)); + $options['url'] = url($_GET['q'], array('absolute' => TRUE)); } - + if (empty($options['count_url'])) { $options['count_url'] = $options['url']; } - + if (module_exists('shorten') && ($service = variable_get('tweetbutton_shorten_service'))) { $url = shorten_url($options['url'], $service); // if www => http:// replacement if enabled @@ -368,10 +366,9 @@ function tweetbutton_tweet_get_attributes($options = array()) { } $options['url'] = $url; } - - + $options += $default_option; - + $attributes = array( 'data-size' => $options['size'], 'data-count' => $options['type'], @@ -393,7 +390,7 @@ function theme_tweetbutton_tweet_display($variables) { drupal_add_js($script_url, array('type' => 'external', 'scope' => 'footer')); $options = $variables['options']; $attributes = tweetbutton_tweet_get_attributes($options); - + $tweetbutton_label = isset($options['tweetbutton_label'])? $options['tweetbutton_label']: t('Tweet'); $tweet_link = l($tweetbutton_label, 'http://twitter.com/share', array('attributes' => $attributes, 'external' => TRUE, 'https' => TRUE)); $link = '
' . $tweet_link . '
'; @@ -410,9 +407,9 @@ function tweetbutton_follow_get_attributes($options) { 'size' => variable_get('tweetbutton_follow_size'), 'language' => variable_get('tweetbutton_language'), ); - + $options += $default_options; - + $attributes = array( 'data-show-count' => $options['show_count'], 'data-show-screen-name' => $options['show_screen_name'], @@ -426,18 +423,18 @@ function tweetbutton_follow_get_attributes($options) { function theme_tweetbutton_follow_display($variables) { $script_url = url('http://platform.twitter.com/widgets.js', array('external' => TRUE, 'https' => TRUE)); drupal_add_js($script_url, array('type' => 'external', 'scope' => 'footer')); - + $options = $variables['options']; $screen_name = $variables['screen_name']; if (empty($screen_name)) { $screen_name = variable_get('tweetbutton_follow_screen_name'); } $follow_user_text = isset($options['tweetbutton_label'])? $options['tweetbutton_label']: t('Follow !screen_name', array('!screen_name' => $screen_name)); - + $twitter_account_link = 'http://twitter.com/' . $screen_name; - + $attributes = tweetbutton_follow_get_attributes($options); - + $follow_link = l($follow_user_text, $twitter_account_link,array('attributes' => $attributes, 'external' => TRUE, 'https' => TRUE)); $link = '
' . $follow_link . '
'; return $link; @@ -448,9 +445,9 @@ function tweetbutton_hashtag_get_attributes($options) { $default_options = array( 'rel_account' => variable_get('tweetbutton_account'), ); - + $options += $default_options; - + $attributes = array( 'data-related' => $options['rel_account'], 'data-lang' => $options['language'] == 'auto'? $language->language: $options['language'], @@ -461,18 +458,19 @@ function tweetbutton_hashtag_get_attributes($options) { function theme_tweetbutton_hashtag_display($variables) { $script_url = url('http://platform.twitter.com/widgets.js', array('external' => TRUE)); drupal_add_js($script_url, array('type' => 'external', 'scope' => 'footer')); - + $options = $variables['options']; $attributes = tweetbutton_hashtag_get_attributes($options); $query = array(); if (!empty($options['tweet_text'])) { $query['tweet_text'] = $options['tweet_text']; } - + if (!empty($variables['hashtag'])) { $query['button_hashtag'] = $variables['hashtag']; } - + $hash_link = l($hash_text, 'http://twitter.com/intent/tweet', array('query' => $query, 'attributes' => $attributes, 'external' => TRUE, 'https' => TRUE)); return '
' . $hash_link . '
'; -} \ No newline at end of file +} +