diff --git a/tests/twitter_block.test b/tests/twitter_block.test index 4e435c5..baa2762 100644 --- a/tests/twitter_block.test +++ b/tests/twitter_block.test @@ -49,6 +49,7 @@ class TwitterBlockTestCase extends DrupalWebTestCase { $twitter_block['info'] = $this->randomName(8); $twitter_block['title'] = $this->randomName(8); $twitter_block['widget_id'] = $this->randomName(8); + $twitter_block['twitter_account'] = $this->randomName(8); $this->drupalPost('admin/structure/block/add-twitter-block', $twitter_block, t('Save block')); // Confirm that the custom Twitter block has been created, and then query the created bid. diff --git a/twitter_block.admin.inc b/twitter_block.admin.inc index 71730c6..ca73af1 100644 --- a/twitter_block.admin.inc +++ b/twitter_block.admin.inc @@ -71,11 +71,12 @@ function twitter_block_add_block_form_submit($form, &$form_state) { 'polite' => $form_state['values']['polite'], ); - // Save the block configuration + // Save the block configuration. $delta = db_insert('twitter_block') ->fields(array( 'info' => $form_state['values']['info'], 'widget_id' => $form_state['values']['widget_id'], + 'twitter_account' => $form_state['values']['twitter_account'], 'data' => serialize($data), )) ->execute(); diff --git a/twitter_block.install b/twitter_block.install index 279aa98..ab1af8e 100644 --- a/twitter_block.install +++ b/twitter_block.install @@ -25,6 +25,13 @@ function twitter_block_schema() { 'default' => '', 'description' => 'Block description.', ), + 'twitter_account' => array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => 'Twitter account.', + ), 'widget_id' => array( 'type' => 'varchar', 'length' => 128, @@ -89,3 +96,16 @@ function twitter_block_update_7200() { return t('Removed any old Twitter Block blocks and installed the new Twitter Block schema.'); } + +/** + * Add column for Twitter account. + */ +function twitter_block_update_7201() { + db_add_field('twitter_block', 'twitter_account', array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => 'twitterapi', + 'description' => 'Twitter account.', + )); +} diff --git a/twitter_block.module b/twitter_block.module index 30c974b..d75a065 100644 --- a/twitter_block.module +++ b/twitter_block.module @@ -84,15 +84,16 @@ function twitter_block_form_block_admin_display_form_alter(&$form, &$form_state, /** * Returns information from database about a user-created (Twitter) block. * - * @param $bid + * @param int $bid * ID of the block to get information for. * - * @return + * @return array * Associative array of information stored in the database for this block. * Array keys: * - bid: Block ID. * - info: Block description. * - widget_id: Widget ID. + * - twitter_account: The Twitter account. * - theme: Theme. * - link_color: Link color. * - width: Width. @@ -157,6 +158,7 @@ function twitter_block_custom_block_form($edit = array()) { $edit += array( 'info' => '', 'widget_id' => '', + 'twitter_account' => '', 'theme' => '', 'link_color' => '', 'width' => '', @@ -184,6 +186,13 @@ function twitter_block_custom_block_form($edit = array()) { '#required' => TRUE, '#description' => t('Each Twitter Block block requires a unique widget ID which determines, among other things, the source (user timeline, favourites, list or search) of the tweets to display. You can view a list of your existing embedded timeline widgets (and their widget IDs) or create new embedded timeline widgets by visiting the widgets section of your settings page (make sure that you\'re logged in). You can determine a widget\'s ID by editing it and inspecting the URL (which should be in the form of twitter.com/settings/widgets/WIDGET_ID/edit) or by looking at the widget\'s embed code (look for data-widget-id="WIDGET_ID").', array('@widgets_section' => 'https://twitter.com/settings/widgets')), ); + $form['twitter_account'] = array( + '#type' => 'textfield', + '#title' => t('Twitter account'), + '#default_value' => $edit['twitter_account'], + '#required' => FALSE, + '#description' => t("This will override the default widget's user, and create a link to Twitter for those users that don't have javascript enabled."), + ); $form['appearance'] = array( '#type' => 'fieldset', '#title' => t('Appearance'), @@ -307,10 +316,11 @@ function twitter_block_block_save($delta = 0, $edit = array()) { /** * Saves a user-created Twitter block in the database. * - * @param $edit + * @param array $edit * Associative array of fields to save. Array keys: * - info: Block description. * - widget_id: Widget ID. + * - twitter_account: Twitter account. * - theme: Theme. * - link_color: Link color. * - width: Width. @@ -321,10 +331,10 @@ function twitter_block_block_save($delta = 0, $edit = array()) { * - tweet_limit: Tweet limit. * - related: Related users. * - polite: ARIA politeness. - * @param $delta + * @param string $delta * Block ID of the block to save. * - * @return + * @return bool * Always returns TRUE. */ function twitter_block_custom_block_save($edit, $delta) { @@ -342,11 +352,12 @@ function twitter_block_custom_block_save($edit, $delta) { 'polite' => $edit['polite'], ); - // Save the block configuration - $delta = db_update('twitter_block') + // Save the block configuration. + db_update('twitter_block') ->fields(array( 'info' => $edit['info'], 'widget_id' => $edit['widget_id'], + 'twitter_account' => $edit['twitter_account'], 'data' => serialize($data), )) ->condition('bid', $delta) @@ -362,19 +373,20 @@ function twitter_block_block_view($delta) { // Load the configuration. $config = twitter_block_block_get($delta); - // Unserialize the timeline + // Unserialize the timeline. $data = unserialize($config['data']); $block = array(); $block['subject'] = check_plain($config['info']); $block['content'] = array( '#theme' => 'link', - '#text' => 'Tweets by @twitterapi', - '#path' => 'https://twitter.com/twitterapi', + '#text' => 'Tweets by @' . $config['twitter_account'], + '#path' => 'https://twitter.com/' . $config['twitter_account'], '#options' => array( 'attributes' => array( 'class' => array('twitter-timeline'), 'data-widget-id' => $config['widget_id'], + 'data-screen-name' => $config['twitter_account'], ), 'html' => FALSE, ),