How do I add custom contextual links in a block?
I know that this blog post is 100 years old, but it still applies:

http://bleen.net/blog/easier-way-add-contextual-links-drupal-7

The basic idea is to make use of hook_contextual_links_view_alter

For example: 

function MYMODULE_contextual_links_view_alter(&amp;$element, &amp;$items) {
  // This hook is called for EVERY set of contextual links
  // on a page.  We first want to check the $element to make
  // sure we are adding a link to the correct list of contextual
  // links. In this case we only want to add a link to blocks
  // created by the "search" module. We just add links using the
  // same array structure as is used by theme_links.
  if (isset($element['#element']['#block']) &amp;&amp; $element['#element']['#block']-&gt;delta == "site_tweets-site_tweets_block") {
    $element['#links']['social-networks'] = array(
      'title' =&gt; 'Edit social network links',
      'href' =&gt; url('/admin/config/system/site-information', array('absolute' =&gt; TRUE)),
    );
  }
}