Hi, for those who wants to have furl like this :
www.yourdomain.com/image-image,name,id.htmlwww.yourdomain.com/categorie-categorie,name,id,page.htmlwww.yourdomain.com/recherche-name,page.htmlwww.yourdomain.com/nouvelles-images,1,page.html(you can see it on my web site :
www.yatahonga.com)
first : in sessions.php
find the url function and replace it by :
function good_name($nom) {
$nom = str_replace(' ', ',', $nom);
$nom = str_replace('_', ',', $nom);
$nom = str_replace('--', ',', $nom);
$nom = str_replace('---', ',', $nom);
$nom = str_replace(',,', ',', $nom);
$nom = str_replace(',,,', ',', $nom);
$nom = str_replace('&', '', $nom);
$nom = str_replace('©', '', $nom);
$nom = str_replace('~', '', $nom);
$nom = str_replace('°', '', $nom);
$nom = str_replace('+', '', $nom);
$nom = str_replace('=', '', $nom);
$accent = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ";
$noaccent = "aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyyby";
$nom = strtr(trim($nom),$accent,$noaccent);
return $nom;
}
function url($url, $amp = "&", $nom = "" ) {
global $l, $user_info;
// on enleve les caracteres spéciaux du nom
$nom=$this->good_name($nom);
$dummy_array = explode("#", $url);
$url = $dummy_array[0];
$url = str_replace('&', '&', $url);
if (!defined('IN_CP')) {
if (strstr($url, 'index.php')) {
$url = str_replace('index.php', '', $url);
}
// POUR LA PAGE SEARCH.PHP
elseif (strstr($url, 'search.php')) {
if (strstr($url, 'page=')) {
preg_match('#page=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('search.php', 'recherche-images,'.$matches[1].'.html', $url);
$query = str_replace('page='.$matches[1].'&', '', $query);
$query = str_replace('&page='.$matches[1], '', $query);
$query = str_replace('page='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else if (strstr($url, 'search_new_images=')) {
preg_match('#search_new_images=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('search.php', 'nouvelles-images,'.$matches[1].'.html', $url);
}
}
else if (strstr($url, 'search_keywords=')) {
//echo "<br>JE SUIS DS SEARCH KEYWORDS<br>";
preg_match('#search_keywords=(.*)&?#', $url, $matches);
if (isset($matches[1])) {
//echo "<br>JE detecte les matchs : ".$matches[1]."<br>";
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
//echo "<br>QUERY : ".$query[1]."<br>";
$url = str_replace('search.php', 'recherche-images,'.$matches[1].'.html', $url);
}
}
else {
$url = str_replace('search.php', 'recherche-images.html', $url);
}
}
// POUR LA PAGE SEARCH_STATS.PHP
elseif (strstr($url, 'search_stats.php')) {
$url = str_replace('search_stats.php', 'recherches-statistiques.html', $url);
}
// POUR LA PAGE CATEGORIE.PHP
elseif (strstr($url, 'categories.php')) {
if (strstr($url, 'cat_id=') && strstr($url, 'page=')) {
preg_match('#cat_id=([0-9]+)&?#', $url, $matches1);
preg_match('#page=([0-9]+)&?#', $url, $matches2);
if (isset($matches1[1]) && isset($matches2[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('categories.php', 'categorie-'.$nom.','.$matches1[1].','.$matches2[1].'.html', $url);
$query = str_replace('cat_id='.$matches1[1].'&', '', $query);
$query = str_replace('&cat_id='.$matches1[1], '', $query);
$query = str_replace('cat_id='.$matches1[1], '', $query);
$query = str_replace('page='.$matches2[1].'&', '', $query);
$query = str_replace('&page='.$matches2[1], '', $query);
$query = str_replace('page='.$matches2[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
elseif (strstr($url, 'cat_id=')) {
preg_match('#cat_id=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('categories.php', 'categorie-'.$nom.','.$matches[1].'.html', $url);
$query = str_replace('cat_id='.$matches[1].'&', '', $query);
$query = str_replace('&cat_id='.$matches[1], '', $query);
$query = str_replace('cat_id='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else {
$url = str_replace('categories.php', 'cat.html', $url);
}
}
// POUR LA PAGE DETAILS.PHP
elseif (strstr($url, 'details.php?image_id=')) {
if (strstr($url, 'image_id=') && strstr($url, 'mode=')) {
preg_match('#image_id=([0-9]+)&?#', $url, $matches1);
preg_match('#mode=([a-zA-Z0-9]+)&?#', $url, $matches2);
if (isset($matches1[1]) && isset($matches2[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('details.php','image-'.$nom.','.$matches1[1].'.'.$matches2[1].'.html', $url);
$query = str_replace('image_id='.$matches1[1].'&', '', $query);
$query = str_replace('&image_id='.$matches1[1], '', $query);
$query = str_replace('image_id='.$matches1[1], '', $query);
$query = str_replace('mode='.$matches2[1].'&', '', $query);
$query = str_replace('&mode='.$matches2[1], '', $query);
$query = str_replace('mode='.$matches2[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
else {
preg_match('#image_id=([0-9]+)&?#', $url, $matches);
if (isset($matches[1])) {
$split = explode('?', $url);
$url = $split[0];
$query = @$split[1];
$url = str_replace('details.php','image-'.$nom.','.$matches[1].'.html', $url);
$query = str_replace('image_id='.$matches[1].'&', '', $query);
$query = str_replace('&image_id='.$matches[1], '', $query);
$query = str_replace('image_id='.$matches[1], '', $query);
if (!empty($query)) {
$url .= '?' . $query;
}
}
}
}
}
if ($this->mode == "get" && strstr($url, $this->session_id)) {
$url .= strpos($url, '?') !== false ? '&' : '?';
$url .= SESSION_NAME."=".$this->session_id;
}
if (!empty($l)) {
$url .= strpos($url, '?') ? '&' : '?';
$url .= "l=".$l;
}
$url = str_replace('&', $amp, $url);
$url .= isset($dummy_array[1]) ? "#".$dummy_array[1] : "";
return $url;
}
// *************************************************************
// FIN URL REWRITING
// *************************************************************
Note that if you want others statics words, you have to change the differents str_replace for search, details and categories
STEP 2 : in functions.phpwherevever you see :
$site_sess->url(ROOT_PATH."details.php?"
AND
$site_sess->url(ROOT_PATH."categories.php?"
just add the thir agurment wich is the cat or image name of course !
ex :
in function get_thumbnail_code(), for the condition if ($showlink), i set :
$thumb = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : ""),0,
$image_name)."\" onclick=\"opendetailwindow()\" target=\"detailwindow\">".$thumb."</a>";
STEP 3 : paging.phpreplace it by this :
<?php
/**************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: paging.php *
* Copyright: (C) 2002 Jan Sorgalla *
* Email: jan@4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7 *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) für weitere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
if (!defined('ROOT_PATH')) {
die("Security violation");
}
class Paging {
var $page,$offset,$perpage,$num_rows_all,$link_args;
var $first,$last,$total_pages,$config,$desc,$next,$back;
function Paging($page = 1, $perpage = 0, $num_rows_all = 0, $link_args = "") {
global $lang, $config;
$this->page = $page;
$this->perpage = $perpage;
$this->num_rows_all = $num_rows_all;
if (!isset($this->page) || !intval($this->page)) {
$this->page = 1;
}
if (!$this->num_rows_all) {
$this->total_pages = 0;
}
elseif ($this->num_rows_all <= $this->perpage) {
$this->total_pages = 1;
}
elseif ($this->num_rows_all % $this->perpage == 0) {
$this->total_pages = $this->num_rows_all / $this->perpage;
}
else {
$this->total_pages = ceil($this->num_rows_all / $this->perpage);
}
if ($this->page > $this->total_pages) {
$this->page = 1;
}
if (!$this->num_rows_all) {
$this->first = 0;
}
else {
$this->first = $this->perpage * $this->page - $this->perpage + 1;
}
if (!$this->num_rows_all) {
$this->last = 0;
}
elseif ($this->page == $this->total_pages) {
$this->last = $this->num_rows_all;
}
else {
$this->last = $this->perpage * $this->page;
}
$this->offset = $this->perpage * $this->page - $this->perpage;
$link_args = ereg_replace("&page=[0-9]*", "", $link_args);
$link_args = ereg_replace("page=[0-9]*&", "", $link_args);
$this->link_args = basename($link_args);
$this->link_args .= preg_match("/\?/",$this->link_args) ? "&" : "?";
$this->desc = $lang['paging_stats'];
$this->paging_next = $lang['paging_next'];
$this->paging_back = $lang['paging_previous'];
$this->paging_lastpage = $lang['paging_lastpage'];
$this->paging_firstpage = $lang['paging_firstpage'];
$this->range = $config['paging_range'];
}
// fct utile pour l'url rewriting
function good_page($url){
// on explode la chaine sur .
$url = explode (".",$url);
//on ne renvoit que l'url sans le .html
return $url[0];
}
function get_paging() {
$html = "";
if ($this->total_pages > 1) {
$page_back = $this->page - 1;
$page_next = $this->page + 1;
if ($page_back > 0) {
$html .= "<a href=\"".$this->good_page($this->link_args).",1.html\" class=\"paging\">".$this->paging_firstpage."</a> ";
$html .= "<a href=\"".$this->good_page($this->link_args).",$page_back.html\" class=\"paging\">".$this->paging_back."</a> ";
}
for ($page_num = 1; $page_num <= $this->total_pages; $page_num++) {
if ($page_num >= ($this->page-$this->range) && $page_num <= ($this->page+$this->range)) {
if ($this->page == $page_num) {
$html .= "<b class=\"pagingon\">$page_num</b> ";
}
else {
$html .= "<a href=\"".$this->good_page($this->link_args).",$page_num.html\" class=\"paging\">$page_num</a> ";
}
}
}
if ($page_next <= $this->total_pages) {
$html .= "<a href=\"".$this->good_page($this->link_args).",$page_next.html\" class=\"paging\">".$this->paging_next."</a> ";
$html .= "<a href=\"".$this->good_page($this->link_args).",$this->total_pages.html\" class=\"paging\">".$this->paging_lastpage."</a>";
}
}
return $html;
}
function get_offset() {
return $this->offset;
}
function get_paging_stats() {
global $site_template;
$search_array = array(
"/".$site_template->start."total_cat_images".$site_template->end."/iU",
"/".$site_template->start."total_pages".$site_template->end."/iU",
"/".$site_template->start."first_page".$site_template->end."/iU",
"/".$site_template->start."last_page".$site_template->end."/iU"
);
$replace_array = array(
$this->num_rows_all,
$this->total_pages,
$this->first,
$this->last
);
$this->desc = preg_replace($search_array, $replace_array, $this->desc);
return $this->desc;
}
} //end of class
?>
STEP 4 : categories.phpin section SHOW IMAGE, juste replace
the $linkarg definition by :
$link_arg = $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id,0,$cat_cache[$cat_id]['cat_name']);
( i just add the cat name
)
STEP 5 : details.phpfor next and prev image url, just add the name of the image like this :
$next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&mode=".$mode : ""),0,$next_image_name);
$prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id.((!empty($mode)) ? "&mode=".$mode : ""),0,$prev_image_name);
STEP 6 : search_form.html (template) and header.html (template too...)for the form, add this : onsubmit="return form_url(this.search_keywords.value); "
(its a redirection function in order to get the name of the query
then add in your header this javascript function:
function form_url(keywords) {
// on remplace les espaces
ok_key = keywords.replace(/ /, ",");
location.href="http://www.YOURDOMAIN.com/recherche-images,"+ok_key+",1.html";
return false;
}
Note that if you change the statics words in STEP 1, you have to change it in this functionSTEP 7 : change your htaccess...
here is mine :
RewriteEngine on
# REWRITE DES PAGES DETAILS
RewriteRule ^/image-(.*),([0-9]+)\.html$ /details.php?image_id=$2 [L]
# CATEGORIES
RewriteRule ^/categorie-(.*),([0-9]+),([0-9]+)\.html$ /categories.php?cat_id=$2&page=$3 [L]
RewriteRule ^/categorie-(.*),([0-9]+)\.html$ /categories.php?cat_id=$2 [L]
# SEARCH
RewriteRule ^/recherche-images\.html$ /search.php [L]
RewriteRule ^/recherche-images,(.*),([0-9]+)\.html$ /search.php?show_result=1&search_keywords=$1&page=$2 [L]
RewriteRule ^/recherche-images,(.*)\.html$ /search.php?show_result=1&search_keywords=$1 [L]
RewriteRule ^recherches-statistiques\.html$ /search_stats.php [L]
RewriteRule ^recherches-statistiques,([0-9]+)\.html$ /search_stats.php?page=$1 [L]
RewriteRule ^/nouvelles-images,1\.html$ /search.php?search_new_images=1 [L]
RewriteRule ^/nouvelles-images,1,([0-9]+)\.html$ /search.php?search_new_images=1&page=$1 [L]
And that's all ! (its quite easy, don't be afraid...)
the main function is function url in sessions.php, its here you have to pay attention for the name of your rewriting
and in all other page, you just have to add the name of categorie, image, search or whatever when you call the function url()
If you understand, you can do it for lighbox.php, member.php, postcard.php etc....
Best regards !
cyril
ps : i hope you understand how i code this and i apologize for my bad english