/**
* Convert urls to search-engine friendly (SEF) urls
*/
function sef_urls_convert(&$html) {
// Rewrite index.php?cat=[category]&page=[page] URLs to index-[category]-page-[page].html
$html = preg_replace('/index\.php\?cat=([0-9]+)(\&|\&)page=([0-9]+)/i','index-$1-page-$3.html',$html);
// Rewrite index.php?cat=[category] URLs to index-[category].html
$html = preg_replace('/index\.php\?cat=([0-9]+)/i','index-$1.html',$html);
// Rewrite thumbnails.php?album=[album]&cat=[category]&page=[category] URLs to thumbnails-[album]-[category]-page-[page].html
$html = preg_replace('/thumbnails\.php\?album=([a-z0-9]+)(\&|\&)cat=([\-0-9]+)(\&|\&)page=([0-9]+)/i','thumbnails-$1-$3-page-$5.html',$html);
// Rewrite thumbnails.php?album=[album]&cat=[category] URLs to thumbnails-[album]-[category].html
$html = preg_replace('/thumbnails\.php\?album=([a-z0-9]+)(\&|\&)cat=([\-0-9]+)/i','thumbnails-$1-$3.html',$html);
#FIX BY DEVELAR
// Rewrite thumbnails.php?album=[album]&page=[category] URLs to thumbnails-[album]-page-[page].html
$html = preg_replace('/thumbnails\.php\?album=([a-z0-9]+)(\&|\&)page=([0-9]+)(\&|\&)sort=([a-z]+)/i','thumbnails-$1-page-$3-sort-$5.html',$html);
// Rewrite thumbnails.php?album=[album]&page=[category] URLs to thumbnails-[album]-page-[page].html
$html = preg_replace('/thumbnails\.php\?album=([a-z0-9]+)(\&|\&)page=([0-9]+)/i','thumbnails-$1-page-$3.html',$html);
// Rewrite thumbnails.php?album=[album]&page=[category]&sort=[sort] URLs to thumbnails-[album]-page-[page].html
$html = preg_replace('/thumbnails\.php\?album=([a-z0-9]+)(\&|\&)page=([0-9]+)(\&|\&)sort=([a-z]+)/i','thumbnails-$1-page-$3-sort-$5.html',$html);
// Rewrite thumbnails.php?album=search&search=[searchterm] URLs to thumbnails-search-[searchterm].html
$html = preg_replace('/thumbnails\.php\?album=search(\&|\&)search=([^"]+)/i','thumbnails-search-$2.html',$html);
// Rewrite thumbnails.php?album=[album] URLs to thumbnails-[album].html
$html = preg_replace('/thumbnails\.php\?album=([a-z0-9]+)/i','thumbnails-$1.html',$html);
// Rewrite displayimage.php?album=[album]&cat=[category]&pos=[position] URLs to displayimage-[album]-[category]-[position].html
$html = preg_replace('/displayimage\.php\?album=([a-z0-9]+)(\&|\&)cat=([\-0-9]+)(\&|\&)pos=([\-0-9]+)/i','displayimage-$1-$3-$5.html',$html);
// Rewrite displayimage.php?album=[album]&pos=[position] URLs to displayimage-[album]-[position].html
$html = preg_replace('/displayimage\.php\?album=([a-z0-9]+)(\&|\&)pos=([\-0-9]+)/i','displayimage-$1-$3.html',$html);
// Rewrite displayimage.php?pos=-[pid] URLs to displayimage-[pid].html
$html = preg_replace('/displayimage\.php\?pos=-([0-9]+)/i','displayimage-$1.html',$html);
// adding filename
$picture_title = $CURRENT_PIC_DATA['title'] ? $CURRENT_PIC_DATA['title'] : strtr(preg_replace("/(.+)\..*?\Z/", "\\1", htmlspecialchars($CURRENT_PIC_DATA['filename'])), "_", " ");
// Rewrite displayimage.php?pid=[photo id]&fullsize=1','" URLs to HQ/[photo id]
$html = preg_replace('/displayimage\.php\?pid=([0-9]+)(\&|\&)fullsize=1/i','$1.html',$html);
// Return modified HTML
return $html;
}
#
# Rewrite index urls
#
RewriteRule index-([0-9]*)\.html index.php?cat=$1 [NC]
RewriteRule index-([0-9]*)-page-([0-9]*)\.html index.php?cat=$1&page=$2 [NC]
#
# Rewrite thumbnail urls
#
RewriteRule thumbnails-([a-z0-9]*)-([\-]?[0-9]*)\.html thumbnails.php?album=$1&cat=$2 [NC]
RewriteRule thumbnails-([a-z0-9]*)-page-([0-9]*)\.html thumbnails.php?album=$1&page=$2 [NC]
#FIX BY DEVELAR
RewriteRule thumbnails-([a-z0-9]+)-page-([0-9]+)-sort-([a-z]+)\.html thumbnails.php?album=$1&page=$2&sort=$3 [NC,L]
RewriteRule thumbnails-([a-z0-9]*)-([\-]?[0-9]*)-page-([0-9]*)\.html thumbnails.php?album=$1&cat=$2&page=$3 [NC]
RewriteRule thumbnails-([0-9]*)\.html thumbnails.php?album=$1 [NC]
RewriteRule thumbnails-search-(.*)\.html thumbnails.php?album=search&search=$1 [NC]
#
# Rewrite displayimage urls
#
RewriteRule displayimage-([a-z0-9]+)-([\-]?[0-9]+)-([\-]?[0-9]+)\.html displayimage.php?album=$1&cat=$2&pos=$3 [NC]
RewriteRule displayimage-([a-z0-9]+)-([\-]?[0-9]+)\.html displayimage.php?album=$1&pos=$2 [NC]
RewriteRule displayimage-([0-9]+)\.html displayimage.php?pos=-$1 [NC]
RewriteRule ([0-9]+)\.html displayimage.php?pid=$1&fullsize=1 [NC]