And added the code (currently in a helper module)

function helper_help($path, $arg) {
  switch ($path) {
    case 'api':
      return '<p>Syntax is:</p>';
  }
}
function helper_menu() {
  $items['api'] = array(
    'title' => 'API',
    'page callback' => 'helper_api',
    'access arguments' => array('access api'),
  );

  return $items;
}
function helper_perm() {
  return array('access api');
}
function helper_api() {
  $q = $_GET["url"];
  if ($q == ""){
    $ret = '<p>http://redir.is/api?url=&lt;Your-URL&gt;</p>
    <p>Result is a XML like:<br />
    &#10;    &amp;lt;url&amp;gt;&lt;br /&gt;&#10;    &amp;nbsp;&amp;nbsp;  &amp;lt;original&amp;gt;http://redir.is/&amp;lt;/original&amp;gt;&lt;br /&gt;&#10;    &amp;nbsp;&amp;nbsp;  &amp;lt;redirect&amp;gt;http://redir.is/x&amp;lt;/redirect&amp;gt;&lt;br /&gt;&#10;    &amp;lt;/url&amp;gt;&#10;    
    </p>
    <p>or</p>
    <p>http://redir.is/api?url=&lt;Your-URL&gt;&amp;format=html</p>
    <p>To get a simple textfile
    </p>';
    return $ret;
  } else {
    if ($_GET["format"] == "html") {
      drupal_set_header('Content-type: text/plain');
      $short = shorturl_shorten ($q);
      print("http://redir.is/" . $short);
    }
    else {
      drupal_set_header('Content-type: text/xml');
      $short = shorturl_shorten ($q);
      print("<url>");
      print("<original>" . $q . "</original>");
      print("<redirect>http://redir.is/" . $short . "</redirect>");
      print("</url>");
    }
  }
}

which returns either html (as plain/text: http://redir.is/api?url=http://redir.is/&format=html) or a xml (http://redir.is/api?url=http://redir.is/)m which makes this module usable to external services.
Like:

  // (....)
  $redir = simplexml_load_file("http://redir.is/api?url=" . $url);
  $redir = $redir->redirect;
  // (....)

Comments

irakli’s picture

Very cool. Thanks for sharing.

mably’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

This issue was filed against the previous Drupal 6/7 module that used this project namespace.

The namespace has been taken over and the module has been replaced by a completely new and unrelated project for Drupal 10/11.

The original code remains available in the 6.x-1.x branch.

Closing this issue as it no longer applies to the current module.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.