Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added shortid support

  • Loading branch information...
commit dbf7cbcbbc33acd3c9a5d1c955da69013cc65a56 1 parent fc832a6
@chregu authored
Showing with 28 additions and 2 deletions.
  1. +27 −2 libs/popoon/components/generators/planet.php
  2. +1 −0  xsl/atom1.xsl
View
29 libs/popoon/components/generators/planet.php
@@ -198,11 +198,15 @@ function mdbResult2XML ($res, $rowField, $cdataFields = array()) {
}
$xml .= '</'.$key.'>';
}
+ if ($rowField == 'entry') {
+ $xml .= '<shortid>'.$this->id2url($row['id']) ."</shortid>";
+ }
$xml .= '</'.$rowField.'>';
-
+
}
+
}
else {
@@ -211,7 +215,7 @@ function mdbResult2XML ($res, $rowField, $cdataFields = array()) {
return $xml;
}
- function url2id($short) {
+ protected function url2id($short) {
$base = 63;
$symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
@@ -227,6 +231,27 @@ function url2id($short) {
return $total;
}
+
+ protected function id2url($val) {
+ if (0 == $val) {
+ return 0;
+ }
+ $base = 63;
+ $symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
+ $result = '';
+ $exp = $oldpow = 1;
+ while ($val > 0 && $exp < 10) {
+
+ $pow = pow($base, $exp++);
+
+ $mod = ($val % $pow);
+ // print $mod ."\n";
+ $result = substr($symbols, $mod / $oldpow, 1) . $result;
+ $val -= $mod;
+ $oldpow = $pow;
+ }
+ return $result;
+ }
}
View
1  xsl/atom1.xsl
@@ -43,6 +43,7 @@
<xsl:value-of select="title"/>
</title>
<link rel="alternate" type="text/html" href="{link}" title="{title}"/>
+ <link rel="shortlink" type="text/html" href="http://planet-php.org/~{shortid}" title="Shortlink to {link}"/>
<author>
<name>
<xsl:choose>
Please sign in to comment.
Something went wrong with that request. Please try again.