From 695610996ae217edf690d5dbbdc2604ad2bc525e Mon Sep 17 00:00:00 2001 From: Carwin Young Date: Wed, 6 Mar 2013 23:50:56 -0600 Subject: [PATCH] =?UTF-8?q?Updated=20token:=207.x-1.4=20=E2=86=92=207.x-1.?= =?UTF-8?q?5.=20Updated=20twitter=5Fusername:=207.x-1.2=20=E2=86=92=207.x-?= =?UTF-8?q?1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contrib/token/tests/token_test.info | 6 +-- .../all/modules/contrib/token/token.drush.inc | 22 +++++++++++ .../all/modules/contrib/token/token.info | 10 ++--- .../sites/all/modules/contrib/token/token.js | 8 +++- .../all/modules/contrib/token/token.module | 36 +++++++++++------- .../all/modules/contrib/token/token.pages.inc | 9 +++-- .../all/modules/contrib/token/token.test | 2 + .../modules/contrib/token/token.tokens.inc | 2 +- .../twitter_username/twitter_username.info | 6 +-- .../twitter_username/twitter_username.install | 37 +++++++++++++++++++ .../twitter_username/twitter_username.module | 22 ++++++----- 11 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 docroot/sites/all/modules/contrib/token/token.drush.inc diff --git a/docroot/sites/all/modules/contrib/token/tests/token_test.info b/docroot/sites/all/modules/contrib/token/tests/token_test.info index a344aa2..141ed5c 100644 --- a/docroot/sites/all/modules/contrib/token/tests/token_test.info +++ b/docroot/sites/all/modules/contrib/token/tests/token_test.info @@ -5,9 +5,9 @@ core = 7.x files[] = token_test.module hidden = TRUE -; Information added by drupal.org packaging script on 2012-09-24 -version = "7.x-1.4" +; Information added by drupal.org packaging script on 2013-02-24 +version = "7.x-1.5" core = "7.x" project = "token" -datestamp = "1348497279" +datestamp = "1361665026" diff --git a/docroot/sites/all/modules/contrib/token/token.drush.inc b/docroot/sites/all/modules/contrib/token/token.drush.inc new file mode 100644 index 0000000..fc32357 --- /dev/null +++ b/docroot/sites/all/modules/contrib/token/token.drush.inc @@ -0,0 +1,22 @@ +' + Drupal.t('Loading token browser...') + '').appendTo('body'); + + // Emulate the AJAX data sent normally so that we get the same theme. + var data = {}; + data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme; + data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token; + dialog.dialog({ title: $(this).attr('title') || Drupal.t('Available tokens'), width: 700, @@ -24,7 +30,7 @@ Drupal.behaviors.tokenDialog = { // Load the token tree using AJAX. dialog.load( url, - {}, + data, function (responseText, textStatus, XMLHttpRequest) { dialog.removeClass('loading'); } diff --git a/docroot/sites/all/modules/contrib/token/token.module b/docroot/sites/all/modules/contrib/token/token.module index 7bba8a7..88bcc60 100644 --- a/docroot/sites/all/modules/contrib/token/token.module +++ b/docroot/sites/all/modules/contrib/token/token.module @@ -78,6 +78,7 @@ function token_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, 'file' => 'token.pages.inc', + 'theme callback' => 'ajax_base_page_theme', ); // Devel token pages. @@ -265,7 +266,7 @@ function token_form_block_admin_configure_alter(&$form, $form_state) { $form['settings']['title']['#description'] .= ' ' . t('This field supports tokens.'); // @todo Figure out why this token validation does not seem to be working here. $form['settings']['title']['#element_validate'][] = 'token_element_validate'; - $form['settings']['title']['#token_types'] = array(); + $form['settings']['title'] += array('#token_types' => array()); } /** @@ -377,23 +378,26 @@ function token_clear_cache() { * @see token_entity_info_alter() * @see http://drupal.org/node/737726 */ -function token_get_entity_mapping($value_type = 'token', $value = NULL) { +function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallback = FALSE) { $mapping = &drupal_static(__FUNCTION__, array()); if (empty($mapping)) { foreach (entity_get_info() as $entity_type => $info) { $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type; } + // Allow modules to alter the mapping array. + drupal_alter('token_entity_mapping', $mapping); } if (!isset($value)) { - return $mapping; + return $value_type == 'token' ? array_flip($mapping) : $mapping; } elseif ($value_type == 'token') { - return array_search($value, $mapping); + $return = array_search($value, $mapping); + return $return !== FALSE ? $return : ($fallback ? $value : FALSE); } elseif ($value_type == 'entity') { - return isset($mapping[$value]) ? $mapping[$value] : FALSE; + return isset($mapping[$value]) ? $mapping[$value] : ($fallback ? $value : FALSE); } } @@ -739,24 +743,28 @@ function token_element_validate_token_context(&$element, &$form_state) { * Implements hook_form_FORM_ID_alter(). */ function token_form_field_ui_field_edit_form_alter(&$form, $form_state) { - if (!isset($form['instance'])) { + if (!isset($form['instance']) || !empty($form['#field']['locked'])) { return; } if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) { // GAH! We can only support global tokens in the upload file directory path. $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate'; - $form['instance']['settings']['file_directory']['#token_types'] = array(); - $form['instance']['settings']['token_tree'] = array( - '#theme' => 'token_tree', - '#token_types' => array(), - '#weight' => $form['instance']['settings']['file_directory']['#weight'] + 0.5, - ); + $form['instance']['settings']['file_directory'] += array('#token_types' => array()); $form['instance']['settings']['file_directory']['#description'] .= ' ' . t('This field supports tokens.'); } // Note that the description is tokenized via token_field_widget_form_alter(). $form['instance']['description']['#description'] .= '
' . t('This field supports tokens.'); + $form['instance']['description']['#element_validate'][] = 'token_element_validate'; + $form['instance']['description'] += array('#token_types' => array()); + + $form['instance']['settings']['token_tree'] = array( + '#theme' => 'token_tree', + '#token_types' => array(), + '#dialog' => TRUE, + '#weight' => $form['instance']['description']['#weight'] + 0.5, + ); } /** @@ -775,6 +783,7 @@ function token_form_system_actions_configure_alter(&$form, $form_state) { $form['token_tree'] = array( '#theme' => 'token_tree', '#token_types' => 'all', + '#dialog' => TRUE, '#weight' => 100, ); // @todo Add token validation to the action fields that can use tokens. @@ -836,10 +845,11 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) { } // Add the token tree UI. - $form['token_tree'] = array( + $form['email']['token_tree'] = array( '#theme' => 'token_tree', '#token_types' => array('user'), '#show_restricted' => TRUE, + '#dialog' => TRUE, '#weight' => 90, ); } diff --git a/docroot/sites/all/modules/contrib/token/token.pages.inc b/docroot/sites/all/modules/contrib/token/token.pages.inc index 905943c..2341a9f 100644 --- a/docroot/sites/all/modules/contrib/token/token.pages.inc +++ b/docroot/sites/all/modules/contrib/token/token.pages.inc @@ -57,7 +57,7 @@ function token_page_output_tree() { $options['dialog'] = FALSE; $output = theme('token_tree', $options); - print '' . drupal_get_css() . drupal_get_js() . ''; + print '' . drupal_get_css() . drupal_get_js() . ''; print '' . $output . ''; drupal_exit(); } @@ -231,7 +231,7 @@ function _token_clean_css_identifier($id) { /** * Menu callback; prints the available tokens and values for an object. */ -function token_devel_token_object($entity_type, $entity) { +function token_devel_token_object($entity_type, $entity, $token_type = NULL) { $header = array( t('Token'), t('Value'), @@ -243,7 +243,10 @@ function token_devel_token_object($entity_type, $entity) { 'values' => TRUE, 'data' => array($entity_type => $entity), ); - $tree = token_build_tree($entity_type, $options); + if (!isset($token_type)) { + $token_type = $entity_type; + } + $tree = token_build_tree($token_type, $options); foreach ($tree as $token => $token_info) { if (!empty($token_info['restricted'])) { continue; diff --git a/docroot/sites/all/modules/contrib/token/token.test b/docroot/sites/all/modules/contrib/token/token.test index b7e9582..59fa645 100644 --- a/docroot/sites/all/modules/contrib/token/token.test +++ b/docroot/sites/all/modules/contrib/token/token.test @@ -676,10 +676,12 @@ class TokenEntityTestCase extends TokenTestHelper { $this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term'); $this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary'); $this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE); + $this->assertIdentical(token_get_entity_mapping('token', 'invalid', TRUE), 'invalid'); $this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node'); $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term'); $this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary'); $this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE); + $this->assertIdentical(token_get_entity_mapping('entity', 'invalid', TRUE), 'invalid'); // Test that when we send the mis-matched entity type into token_replace() // that we still get the tokens replaced. diff --git a/docroot/sites/all/modules/contrib/token/token.tokens.inc b/docroot/sites/all/modules/contrib/token/token.tokens.inc index 3dc2d3b..e0c0b5e 100644 --- a/docroot/sites/all/modules/contrib/token/token.tokens.inc +++ b/docroot/sites/all/modules/contrib/token/token.tokens.inc @@ -80,7 +80,7 @@ function token_token_info_alter(&$info) { foreach ($date_format_types as $date_format_type => $date_format_type_info) { if (!isset($info['tokens']['date'][$date_format_type])) { $info['tokens']['date'][$date_format_type] = array( - 'name' => $date_format_type_info['title'], + 'name' => check_plain($date_format_type_info['title']), 'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))), 'module' => 'token', ); diff --git a/docroot/sites/all/modules/contrib/twitter_username/twitter_username.info b/docroot/sites/all/modules/contrib/twitter_username/twitter_username.info index 6b533e1..9dd77ba 100644 --- a/docroot/sites/all/modules/contrib/twitter_username/twitter_username.info +++ b/docroot/sites/all/modules/contrib/twitter_username/twitter_username.info @@ -3,9 +3,9 @@ description = Defines simple field for handling twitter username (ex: user profi core = 7.x package = Fields -; Information added by drupal.org packaging script on 2012-10-13 -version = "7.x-1.2" +; Information added by drupal.org packaging script on 2013-03-02 +version = "7.x-1.3" core = "7.x" project = "twitter_username" -datestamp = "1350126411" +datestamp = "1362226514" diff --git a/docroot/sites/all/modules/contrib/twitter_username/twitter_username.install b/docroot/sites/all/modules/contrib/twitter_username/twitter_username.install index 05a505a..b16ba43 100644 --- a/docroot/sites/all/modules/contrib/twitter_username/twitter_username.install +++ b/docroot/sites/all/modules/contrib/twitter_username/twitter_username.install @@ -19,3 +19,40 @@ function twitter_username_field_schema($field) { ), ); } + + +/** + * Update formatter machine_name to avoid conflict + */ +function twitter_username_update_7001() { + // Get twitter_username fields + $twitter_username_fields = array(); + foreach (field_info_fields() as $field_name => $field) { + if ($field['type'] == 'twitter_username') { + $twitter_username_fields[$field_name] = $field; + } + } + + // Loop throught instances / bundles / fields + foreach (field_info_instances() as $entity_type => $bundles) { + foreach ($bundles as $bundle_name => $fields) { + foreach($fields as $field_name => $field_instance) { + // If the field type is twitter_username + if (isset($twitter_username_fields[$field_name])) { + // Loop through view_mode + $need_update = FALSE; + foreach($field_instance['display'] as $view_mode => $display) { + // If formatter is defined by twitter_username, update instance + if ($display['type'] == 'default' || $display['type'] == 'link') { + $need_update = TRUE; + $field_instance['display'][$view_mode]['type'] = 'twitter_username_' . $display['type']; + } + } + if ($need_update) { + field_update_instance($field_instance); + } + } + } + } + } +} \ No newline at end of file diff --git a/docroot/sites/all/modules/contrib/twitter_username/twitter_username.module b/docroot/sites/all/modules/contrib/twitter_username/twitter_username.module index c07dfef..5e99435 100644 --- a/docroot/sites/all/modules/contrib/twitter_username/twitter_username.module +++ b/docroot/sites/all/modules/contrib/twitter_username/twitter_username.module @@ -74,9 +74,13 @@ function twitter_username_field_validate($entity_type, $entity, $field, $instanc } // Ensure the username is actually registered. elseif ($instance['settings']['validate_existance']) { - // Query the Twitter API. - $url = url('http://api.twitter.com/1/users/show.xml', array('external' => TRUE, 'query' => array('screen_name' => $item['twitter_username']))); - $response = drupal_http_request($url); + // Query the Twitter User page. + // Since v1.1, we could not request the API with OAuth token. + $url = url( + 'https://twitter.com/' .$item['twitter_username'], + array('external' => TRUE) + ); + $response = drupal_http_request($url, array('method'=>'HEAD')); // HTTP status code 404 means the username doesn't exist. if ($response->code == 404) { @@ -150,11 +154,11 @@ function twitter_username_field_instance_settings_form($field, $instance) { */ function twitter_username_field_formatter_info() { return array( - 'default' => array( + 'twitter_username_default' => array( 'label' => t("Twitter username, as plain text"), 'field types' => array('twitter_username'), ), - 'link' => array( + 'twitter_username_link' => array( 'label' => t("Twitter username, as link"), 'field types' => array('twitter_username'), ), @@ -178,21 +182,21 @@ function twitter_username_field_formatter_view($entity_type, $entity, $field, $i */ function twitter_username_theme() { return array( - 'twitter_username_formatter_default' => array( + 'twitter_username_formatter_twitter_username_default' => array( 'variables' => array('element' => NULL), ), - 'twitter_username_formatter_link' => array( + 'twitter_username_formatter_twitter_username_link' => array( 'variables' => array('element' => NULL), ), ); } -function theme_twitter_username_formatter_default($vars) { +function theme_twitter_username_formatter_twitter_username_default($vars) { $twitter_username = check_plain($vars['element']['twitter_username']); return "@" . $twitter_username; } -function theme_twitter_username_formatter_link($vars) { +function theme_twitter_username_formatter_twitter_username_link($vars) { $twitter_username = check_plain($vars['element']['twitter_username']); return l("@" . $twitter_username, 'http://twitter.com/' . $twitter_username); }