diff --git a/amp.admin.inc b/amp.admin.inc index cd9d1f9..268f88d 100644 --- a/amp.admin.inc +++ b/amp.admin.inc @@ -9,6 +9,7 @@ * Form constructor for the AMP administration form. * * @ingroup forms + * * @see amp_admin_form_validate() * @see amp_admin_form_submit() */ @@ -33,7 +34,10 @@ function amp_admin_form($form, &$form_state) { '#default_value' => variable_get('amp_google_analytics_id'), '#size' => 15, '#maxlength' => 20, - '#description' => t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, register your site with Google Analytics, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. Find more information in the documentation.', array('@analytics' => 'http://www.google.com/analytics/', '@webpropertyid' => url('https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts', array('fragment' => 'webProperty')))), + '#description' => t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, register your site with Google Analytics, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. Find more information in the documentation.', array( + '@analytics' => 'http://www.google.com/analytics/', + '@webpropertyid' => url('https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts', array('fragment' => 'webProperty')) + )), ); $form['amp_google_adsense_id'] = array( '#type' => 'textfield', @@ -66,8 +70,10 @@ function amp_admin_form($form, &$form_state) { '#title' => t('amp-pixel domain name'), '#default_value' => variable_get('amp_pixel_domain_name'), '#description' => t('The domain name where the tracking pixel will be loaded: do not include http or https.'), - '#states' => array('visible' => array( - ':input[name="amp_pixel"]' => array('checked' => TRUE)) + '#states' => array( + 'visible' => array( + ':input[name="amp_pixel"]' => array('checked' => TRUE) + ) ), ); $form['pixel_group']['amp_pixel_query_string'] = array( @@ -75,8 +81,10 @@ function amp_admin_form($form, &$form_state) { '#title' => t('amp-pixel query path'), '#default_value' => variable_get('amp_pixel_query_string'), '#description' => t('The path at the domain where the GET request will be received, e.g. "pixel" in example.com/pixel?RANDOM.'), - '#states' => array('visible' => array( - ':input[name="amp_pixel"]' => array('checked' => TRUE)) + '#states' => array( + 'visible' => array( + ':input[name="amp_pixel"]' => array('checked' => TRUE) + ) ), ); $form['pixel_group']['amp_pixel_random_number'] = array( @@ -84,8 +92,10 @@ function amp_admin_form($form, &$form_state) { '#title' => t('Random number'), '#default_value' => variable_get('amp_pixel_random_number'), '#description' => t('Use the special string RANDOM to add a random number to the URL if required. Find more information in the amp-pixel documentation.'), - '#states' => array('visible' => array( - ':input[name="amp_pixel"]' => array('checked' => TRUE)) + '#states' => array( + 'visible' => array( + ':input[name="amp_pixel"]' => array('checked' => TRUE) + ) ), ); @@ -102,26 +112,23 @@ function amp_admin_form($form, &$form_state) { $form['amp_library']['amp_library_warnings_display'] = array( '#type' => 'checkbox', '#title' => t('Debugging: Show AMP PHP library warnings in all amp text formatters for all users'), - '#default_value' => variable_get('amp_library_warnings_display', false), - '#description' => t('
This is a sample
$html_header $amp_html $original_html" . $amp->warningsHumanHtml() . "" - ); + $html_header = PHP_EOL . PHP_EOL . 'OUTPUT HTML' . PHP_EOL; + $html_header .= '-------------' . PHP_EOL; + $html = '' . PHP_EOL . + '' . PHP_EOL . + '' . PHP_EOL . + '' . PHP_EOL . + '
This is a sample
$html_header $amp_html $original_html" . $amp->warningsHumanHtml() . "" + ); } /** * Implements hook_theme(). */ function amp_theme() { - $theme = array( + $theme = array( 'amp_ad' => array( 'variables' => array( 'adtype' => NULL, @@ -254,7 +280,7 @@ function amp_preprocess_amp_video(&$variables) { * Implements hook_element_info(). */ function amp_element_info() { - // AMP Analytics element + // AMP Analytics element. $types['amp_analytics'] = array( '#account' => NULL, '#analytics_attributes_array' => [], @@ -266,16 +292,16 @@ function amp_element_info() { } /** - * #pre_render callback to render amp_analytics with js library added to head. + * The #pre_render callback to render amp_analytics with js library added to head. * - * @param $elements + * @param array $element * A render array for amp analytics elements. * - * @return + * @return array $element * The passed-in element with the js library necessary for the amp-analytics * element added to head. */ -function amp_pre_render_amp_analytics($element) { +function amp_pre_render_amp_analytics(array $element) { $head_js = array( '#tag' => 'script', '#type' => 'html_tag', @@ -311,7 +337,7 @@ function amp_is_amp_request() { // Get current URL. $current_url = url(current_path(), array('absolute' => TRUE)); - // Check if URL contains the amp parameter + // Check if URL contains the amp parameter. if (isset($_GET['amp'])) { // Get system path. $system_path = drupal_lookup_path('source', $path); @@ -500,11 +526,11 @@ function amp_block_info() { $block_ids = array(1, 2, 3, 4); foreach ($block_ids as $block_id) { $blocks['amp_google_adsense_' . $block_id] = array( - 'info' => t('AMP Google Adsense ' . $block_id), + 'info' => t('AMP Google Adsense @block_id', array('@block_id' => $block_id)), 'cache' => DRUPAL_NO_CACHE, ); $blocks['amp_google_doubleclick_' . $block_id] = array( - 'info' => t('AMP Google DoubleClick for Publishers ' . $block_id), + 'info' => t('AMP Google DoubleClick for Publishers @block_id', array('@block_id' => $block_id)), 'cache' => DRUPAL_NO_CACHE, ); } @@ -644,8 +670,8 @@ function amp_block_view($delta = '') { } /** -* Implements hook_field_formatter_info(). -*/ + * Implements hook_field_formatter_info(). + */ function amp_field_formatter_info() { return array( 'amp_text' => array( @@ -684,7 +710,12 @@ function amp_field_formatter_info() { 'label' => t('AMP image'), 'description' => t('Display an AMP image file.'), 'field types' => array('image'), - 'settings' => array('image_style' => '', 'image_link' => '', 'amp_layout' => 'responsive', 'amp_fixed_height' => '300'), + 'settings' => array( + 'image_style' => '', + 'image_link' => '', + 'amp_layout' => 'responsive', + 'amp_fixed_height' => '300' + ), ), 'amp_iframe' => array( 'label' => t('AMP iframe'), @@ -756,8 +787,8 @@ function amp_field_formatter_settings_form($field, $instance, $view_mode, $form, '#type' => 'textfield', '#states' => array( 'visible' => array( - ':input[name="fields[' .$field['field_name'] . '][settings_edit_form][settings][amp_layout]"]' => - array('value' => 'fixed-height')) + ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][amp_layout]"]' => array('value' => 'fixed-height') + ) ), '#size' => 10, '#default_value' => $settings['amp_fixed_height'], @@ -803,7 +834,7 @@ function amp_field_formatter_settings_summary($field, $instance, $view_mode) { } if (strpos($display['type'], 'amp_video') !== FALSE) { - $summary[] = t('Dimensions for aspect ratio: @width' . 'px x @height' . 'px', array('@width' => $settings['amp_video_width'], '@height' => $settings['amp_video_height'])); + $summary[] = t('Dimensions for aspect ratio: @width x @height', array('@width' => $settings['amp_video_width'] . 'px', '@height' => $settings['amp_video_height'] . 'px')); } if (strpos($display['type'], 'amp_image') !== FALSE) { @@ -832,7 +863,7 @@ function amp_field_formatter_settings_summary($field, $instance, $view_mode) { $layout_setting = $settings['amp_layout']; if (isset($layout_options[$layout_setting])) { - $summary[] = t('Layout: @setting', array('@setting' => $layout_options[$layout_setting])); + $summary[] = t('Layout: @setting', array('@setting' => $layout_options[$layout_setting])); if ($layout_options[$layout_setting] === 'fixed-height') { $summary[] = t('Fixed height: @height', array('@height' => $settings['amp_fixed_height'])); @@ -869,7 +900,7 @@ function amp_field_formatter_view($entity_type, $entity, $field, $instance, $lan $output = _text_sanitize($instance, $langcode, $item, 'value'); $amp_content = _amp_convert_markup_to_amp($output); $element[$delta] = array('#markup' => $amp_content['amp_markup']); - if (isset($_GET['warnfix']) || variable_get('amp_library_warnings_display', false)) { + if (isset($_GET['warnfix']) || variable_get('amp_library_warnings_display', FALSE)) { $element[$delta]['#markup'] .= '
' . $amp_content['amp_warnings'] . ''; } _amp_add_component_libraries($amp_content['amp_components']); @@ -884,7 +915,7 @@ function amp_field_formatter_view($entity_type, $entity, $field, $instance, $lan } $amp_content = _amp_convert_markup_to_amp($output); $element[$delta] = array('#markup' => $amp_content['amp_markup']); - if (isset($_GET['warnfix']) || variable_get('amp_library_warnings_display', false)) { + if (isset($_GET['warnfix']) || variable_get('amp_library_warnings_display', FALSE)) { $element[$delta]['#markup'] .= '
' . $amp_content['amp_warnings'] . ''; } _amp_add_component_libraries($amp_content['amp_components']); @@ -902,7 +933,7 @@ function amp_field_formatter_view($entity_type, $entity, $field, $instance, $lan } $amp_content = _amp_convert_markup_to_amp($output); $element[$delta] = array('#markup' => $amp_content['amp_markup']); - if (isset($_GET['warnfix']) || variable_get('amp_library_warnings_display', false)) { + if (isset($_GET['warnfix']) || variable_get('amp_library_warnings_display', FALSE)) { $element[$delta]['#markup'] .= '
' . $amp_content['amp_warnings'] . ''; } _amp_add_component_libraries($amp_content['amp_components']); @@ -977,7 +1008,8 @@ function _amp_get_layouts() { /** * Use AMP class from library for conversion of text to AMP HTML. * - * @return AMP + * @return object + * The AMP object. */ function _amp_create_amp_converter() { return new AMP(); @@ -989,6 +1021,7 @@ function _amp_create_amp_converter() { * * @param string $markup * The markup to be converted. + * * @return array $amp_content * An array containing the following: * - amp_markup: The AMP HTML. @@ -1013,11 +1046,11 @@ function _amp_convert_markup_to_amp($markup) { function _amp_add_component_libraries(array $components) { $component_definitions = _amp_get_amp_js(); - /** + /* * @var string $component_name * @var string $component_url */ - foreach($components as $component_name => $component_url) { + foreach ($components as $component_name => $component_url) { if (isset($component_definitions[$component_name])) { $element = array( '#tag' => 'script', diff --git a/templates/amp-pixel.tpl.php b/templates/amp-pixel.tpl.php index e9a0565..98988c3 100644 --- a/templates/amp-pixel.tpl.php +++ b/templates/amp-pixel.tpl.php @@ -7,7 +7,7 @@ * Available variables: * - domain: The domain name for the amp-pixel. * - query_string: The path for the query string. - * - subs: An array of possible variable substitutions + * - subs: An array of possible variable substitutions. * * @see template_preprocess_amp_pixel() */ @@ -15,114 +15,143 @@ $subDetails) { - if ($subDetails['active'] === TRUE) { - $activeSubs = array_merge($activeSubs, array($sub => $subDetails)); - } - } + foreach ($subs as $sub => $sub_details): + if ($sub_details['active'] === TRUE): + $active_subs = array_merge($active_subs, array($sub => $sub_details)); + endif; + endforeach; ?> - +