Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added redirector for short urls

(generating the code is done via a fork of the liipto code)
  • Loading branch information...
commit 07b81e62d169cc89d33f65edfbd8c08711988d9b 1 parent edf163b
@chregu authored
View
38 libs/popoon/components/generators/planet.php
@@ -19,7 +19,25 @@ function init($attribs)
function DomStart(&$xml)
{
- include_once("MDB2.php");
+
+ include_once("MDB2.php");
+ if ( $redirect = $this->getParameterDefault("redirect")) {
+ $this->db = MDB2::Connect($GLOBALS['BX_config']['dsn']);
+ $id = $this->url2id($redirect);
+ if ($id) {
+ $query = "select link from entries where ID = $id";
+ $link = $this->db->queryOne($query);
+ if ($link) {
+ header("Location: $link", 301);
+ die();
+ }
+ }
+
+ header("Location: http://planet-php.net/", 302);
+ die();
+ }
+
+
if (!isset($GLOBALS['BX_config']['webTimezone'])) {
$GLOBALS['BX_config']['webTimezone'] = $GLOBALS['BX_config']['serverTimezone'];
}
@@ -192,6 +210,24 @@ function mdbResult2XML ($res, $rowField, $cdataFields = array()) {
}
return $xml;
}
+
+ function url2id($short) {
+ $base = 63;
+ $symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
+
+ $len = strlen($short);
+ $total = 0;
+ for ($i = 0; $i < $len;$i++) {
+ $pos = strpos($symbols,$short{$i});
+ $multi = pow($base,$len - $i - 1);
+ $c = $pos * $multi . "\n";
+ $total += $c;
+
+ }
+
+ return $total;
+ }
+
}
View
9 sitemap/sitemap.xml
@@ -49,6 +49,15 @@
<map:pipeline>
<map:select type="uri">
+ <map:when test="/~">
+ <map:match type="uri" pattern="~*">
+ <map:generate type="planet">
+ <map:parameter name="db" value="config://dsn"/>
+ <map:parameter name="redirect" value="{1}"/>
+ </map:generate>
+ </map:match>
+ </map:when>
+
<map:when test="/search">
<map:match type="uri" pattern="search/*">
<map:generate type="planet">
Please sign in to comment.
Something went wrong with that request. Please try again.