diff --git a/google_plusone.admin.inc b/google_plusone.admin.inc index 75718c5..c7f183f 100644 --- a/google_plusone.admin.inc +++ b/google_plusone.admin.inc @@ -12,7 +12,7 @@ */ function google_plusone_admin_settings($form) { - // Custom javascript code to preview in real-time the button + // Custom javascript code to preview in real-time the button. drupal_add_js(drupal_get_path('module', 'google_plusone') . '/google_plusone.admin.js'); drupal_add_js('https://apis.google.com/js/plusone.js', 'external'); @@ -23,7 +23,6 @@ function google_plusone_admin_settings($form) { $locations[$name] = $info['label']; } - $form['display'] = array( '#type' => 'fieldset', '#title' => t('Display Settings for nodes'), @@ -63,16 +62,18 @@ function google_plusone_admin_settings($form) { $default = array( 'annotation' => 'bubble', 'width' => '250', - 'size' => '', // standard + // Standard. + 'size' => '', 'css' => 'margin: 0 1em 1em 1em;float:right', 'syntax' => 'g:plusone', - 'alias' => 'aliased' + 'alias' => 'aliased', ); $button_settings = array_merge($default, variable_get('google_plusone_button_settings', array())); $form['google_plusone_button_settings'] = array( '#type' => 'fieldset', '#title' => t('Button Settings for nodes'), - '#tree' => TRUE, // All the options in this fieldset will be grouped in 1 single variable. + // All the options in this fieldset will be grouped in 1 single variable. + '#tree' => TRUE, '#description' => google_plusone_build_preview_button($available_sizes), ); $form['google_plusone_button_settings']['annotation'] = array( @@ -117,17 +118,18 @@ function google_plusone_admin_settings($form) { ); $default_advanced = array( - 'lang' => '', - 'scope' => 'page_bottom', - 'parsetags' => 'onload', - 'async' => 1, + 'lang' => '', + 'scope' => 'page_bottom', + 'parsetags' => 'onload', + 'async' => 1, ); $config = array_merge($default_advanced, variable_get('google_plusone_advanced_settings', $default_advanced)); $form['google_plusone_advanced_settings'] = array( '#type' => 'fieldset', '#title' => t('Advanced Settings'), '#collapsed' => TRUE, - '#tree' => TRUE, // All the options in this fieldset will be grouped in 1 single variable. + // All the options in this fieldset will be grouped in 1 single variable. + '#tree' => TRUE, '#collapsible' => TRUE, '#description' => t('Get more information about these options from the documentation of the Google +1 API.', array('@api-doc' => 'https://developers.google.com/+/plugins/+1button/')), ); @@ -180,8 +182,8 @@ function google_plusone_build_preview_button($sizes) { return $output; } -/* - * Trim and polish text input fields +/** + * Trim and polish text input fields. */ function google_plusone_admin_settings_validate($form, &$form_state) { $form_state['values']['google_plusone_button_settings']['css'] = google_plusone_trim($form_state['values']['google_plusone_button_settings']['css'], ';'); @@ -189,16 +191,18 @@ function google_plusone_admin_settings_validate($form, &$form_state) { } /** - * Helper function to trim whitespace and make sure to remove - * the last character if it is a delimiter. + * Helper function to format list items. * - * @param $list - * A string representing a list of items - * @param $delimiter + * Trim whitespace and make sure to remove the last character if it is a + * delimiter. + * + * @param string $list + * A string representing a list of items. + * @param string $delimiter * A string that contains a delimiter. - * @return - * A whitespace-trimmed string * + * @return string + * A whitespace-trimmed string. */ function google_plusone_trim($list, $delimiter) { $list = trim(check_plain($list)); @@ -213,7 +217,8 @@ function google_plusone_trim($list, $delimiter) { /** * Page callback for previewing the Google+ badge in block configuration page. - * It's meant to be called from an iframe element + * + * It's meant to be called from an iframe element. */ function google_plusone_demo_badge_preview() { @@ -222,7 +227,7 @@ function google_plusone_demo_badge_preview() { 'style' => $_GET['sty_'], 'width' => $_GET['wd_'], 'theme' => $_GET['thm_'], - 'custom_name' => $_GET['cm_'] + 'custom_name' => $_GET['cm_'], ); $add_js = &drupal_static('google_plusone_js_added', FALSE); @@ -233,8 +238,8 @@ function google_plusone_demo_badge_preview() { $badge = theme('google_plusone_badge', $variables); $output = $region['google_plusone']['#markup']; $output .= '' . $badge; - $output .= '

' . t('HTML badge source:') . '
' . check_plain($badge). '
'; - $output .= '
' . t('Script source') . '
' . check_plain($region['google_plusone']['#markup']). '
'; + $output .= '

' . t('HTML badge source:') . '
' . check_plain($badge) . '
'; + $output .= '
' . t('Script source') . '
' . check_plain($region['google_plusone']['#markup']) . '
'; echo $output; exit; } diff --git a/google_plusone.admin.js b/google_plusone.admin.js index f27cbe0..3c5d49e 100644 --- a/google_plusone.admin.js +++ b/google_plusone.admin.js @@ -31,4 +31,4 @@ } }; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/google_plusone.install b/google_plusone.install index 22e4429..1ba4c16 100644 --- a/google_plusone.install +++ b/google_plusone.install @@ -28,11 +28,14 @@ function google_plusone_uninstall() { } /** - * 'count' parameter has been deprecated in favor of 'annotation' in the Google +1 API * Updating variables according to the new API. + * + * 'count' parameter has been deprecated in favor of 'annotation' in the + * Google +1 API. + * */ function google_plusone_update_7001() { - // Updating settings of the G+ button for the node + // Updating settings of the G+ button for the node. $button_settings = variable_get('google_plusone_button_settings', 0); if (isset($button_settings['count'])) { $button_settings['annotation'] = $button_settings['count'] ? 'none' : 'bubble'; @@ -40,7 +43,7 @@ function google_plusone_update_7001() { unset($button_settings['count']); variable_set('google_plusone_button_settings', $button_settings); } - // Same for the block settings + // Same for the block settings. $block_settings = variable_get('google_plusone_block_settings', 0); if (isset($block_settings['count'])) { $block_settings['annotation'] = $button_settings['count'] ? 'none' : 'bubble'; @@ -51,4 +54,4 @@ function google_plusone_update_7001() { unset($block_settings['count']); variable_set('google_plusone_block_settings', $block_settings); } -} \ No newline at end of file +} diff --git a/google_plusone.module b/google_plusone.module index dd9578e..824432d 100644 --- a/google_plusone.module +++ b/google_plusone.module @@ -1,4 +1,8 @@ 'g:plusone', 'annotation' => 'bubble', 'width' => '250', - 'alias' => 'aliased' + 'alias' => 'aliased', ), ), 'google_plusone_badge' => array( @@ -60,9 +64,9 @@ function google_plusone_theme() { 'style' => 'standardbadge', 'width' => '300', 'theme' => 'light', - 'custom_name' => '' + 'custom_name' => '', ), - ) + ), ); } @@ -80,10 +84,11 @@ function google_plusone_node_view($node, $view_mode) { $default = array( 'annotation' => 'bubble', 'width' => '250', - 'size' => '', // standard + // Standard. + 'size' => '', 'css' => 'margin: 0 1em 1em 1em;float:right', 'syntax' => 'g:plusone', - 'alias' => 'aliased' + 'alias' => 'aliased', ); $button_settings = array_merge($default, variable_get('google_plusone_button_settings', array())); $settings = array_merge($button_settings, variable_get('google_plusone_block_settings', array())); @@ -97,8 +102,8 @@ function google_plusone_node_view($node, $view_mode) { } if (!empty($locations[$view_mode]) && !empty($locations['link'])) { $node->content['links']['#links']['node_google_plusone_link'] = array( - 'title' => theme('google_plusone_button__' . $node->type, $settings), - 'html' => TRUE, + 'title' => theme('google_plusone_button__' . $node->type, $settings), + 'html' => TRUE, ); } } @@ -107,7 +112,7 @@ function google_plusone_node_view($node, $view_mode) { /** * Returns HTML for the Google +1 button. * - * @param $variables + * @param array $variables * An associative array containing: * - syntax: (optional) A string. If contains 'g:plusone' will be used that syntax. Otherwise, HTML5 syntax by default. * - url: (optional) A string containing the URL to use in the button, or '' (language-aware) @@ -127,7 +132,7 @@ function theme_google_plusone_button($variables) { $add_js = &drupal_static('google_plusone_js_added', FALSE); $add_js = TRUE; - // URL negotiation + // URL negotiation. $url = ''; if (!empty($variables['node']->nid)) { if ($variables['alias'] === 'aliased') { @@ -137,9 +142,11 @@ function theme_google_plusone_button($variables) { $url = url('node/' . $variables['node']->nid, array('absolute' => TRUE, 'alias' => TRUE)); } } - elseif (!empty($variables['url'])) { // See block settings to understand the 'url' setting + // See block settings to understand the 'url' setting. + elseif (!empty($variables['url'])) { if ($variables['url'] === '') { - $url = url('', array('absolute' => TRUE)); // language-aware + // Language-aware. + $url = url('', array('absolute' => TRUE)); } else { $url = check_url($variables['url']); @@ -147,7 +154,8 @@ function theme_google_plusone_button($variables) { } $syntax = empty($variables['syntax']) ? '' : $variables['syntax']; - $data = $syntax === 'g:plusone' ? '' : 'data-'; // HTML5 valid attributes must have 'data-' prefix + // HTML5 valid attributes must have 'data-' prefix. + $data = $syntax === 'g:plusone' ? '' : 'data-'; $url = empty($url) ? '' : $data . 'href="' . $url . '" '; $size = empty($variables['size']) ? '' : $data . 'size="' . check_plain($variables['size']) . '" '; $annotation = empty($variables['annotation']) ? '' : $data . 'annotation="' . check_plain($variables['annotation']) . '" '; @@ -155,10 +163,10 @@ function theme_google_plusone_button($variables) { $tag_start = $syntax === 'g:plusone' ? '' : '>'; - // Putting it all together + // Putting it all together. $button = $tag_start . $url . $size . $annotation . $width . $tag_end; - // Wrap it and serve it + // Wrap it and serve it. if ($variables['css'] !== 'nowrapper') { $css = empty($variables['css']) ? '' : 'style="' . check_plain($variables['css']) . '"'; $button = '
' . $button . '
'; @@ -170,7 +178,7 @@ function theme_google_plusone_button($variables) { /** * Returns HTML for the Google +1 badge. * - * @param $variables + * @param array $variables * An associative array containing: * - page_id: (required) A URL of the Google+ page. Example 'https://plus.google.com/109000232948849684578' * - style: (optional) A string 'badge', 'smallbadge', 'smallicon', 'mediumicon', 'largeicon'. By default 'badge' @@ -186,7 +194,7 @@ function theme_google_plusone_badge($variables) { // in google_plusone_page_alter(). $add_js = &drupal_static('google_plusone_js_added', FALSE); - // The URL with the page id is mandatory + // The URL with the page id is mandatory. if (empty($variables['page_id'])) { return ''; } @@ -198,13 +206,13 @@ function theme_google_plusone_badge($variables) { 'mediumicon' => '32', 'largeicon' => '64'); - if (key_exists($variables['style'], $icon_sizes)) { + if (array_key_exists($variables['style'], $icon_sizes)) { $custom_name = check_plain($variables['custom_name']); $icon_size = $icon_sizes[$variables['style']]; $badge = ''; if ($icon_size === '64') { $badge .= ''; - $badge .= '
' . t($custom_name) . '
' . t('on') .' Google+
'; + $badge .= '
' . t($custom_name) . '
' . t('on') . ' Google+'; } elseif ($icon_size === '32') { $badge .= '' . t($custom_name) . ''; @@ -222,10 +230,12 @@ function theme_google_plusone_badge($variables) { $width = (int) $variables['width']; $height = 131; if (($variables['style'] === 'small_badge') && ($width >= 170)) { - $height = 69; // Calculations based on what you get in the Google Badge Tool. + // Calculations based on what you get in the Google Badge Tool. + $height = 69; } $theme = check_plain($variables['theme']); - $syntax = 'HTML5'; // todo: provide option in block settings. + // TODO: provide option in block settings.. + $syntax = 'HTML5'; $tag_start = $syntax === 'g:plus' ? '' : '>'; $badge = '
' . $tag_start . ' data-href="' . $page_id . '" data-theme="' . $theme . '" data-height="' . $height . '" data-width="' . $width . '"' . $tag_end . '
'; @@ -236,11 +246,11 @@ function theme_google_plusone_badge($variables) { /** * Implements hook_page_alter(). + * * Adds JavaScript to the appropriate scope/region of the page. * * Note: It can't be added through drupal_add_js() due of the * JavaScript object declared inside the