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=<Your-URL></p>
<p>Result is a XML like:<br />
&lt;url&gt;<br /> &nbsp;&nbsp; &lt;original&gt;http://redir.is/&lt;/original&gt;<br /> &nbsp;&nbsp; &lt;redirect&gt;http://redir.is/x&lt;/redirect&gt;<br /> &lt;/url&gt;
</p>
<p>or</p>
<p>http://redir.is/api?url=<Your-URL>&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
Comment #1
irakli commentedVery cool. Thanks for sharing.
Comment #2
mably commentedThis 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.