/************************* Coppermine Photo Gallery ************************ Copyright (c) 2003-2005 Coppermine Dev Team v1.1 originaly written by Gregory DEMAR This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ******************************************** Coppermine version: 1.4.2 $Source: /cvsroot/coppermine/devel/plugins/sef_urls/codebase.php,v $ $Revision: 1.8 $ $Author: gaugau $ $Date: 2005/10/25 01:16:09 $ **********************************************/ if (!defined('IN_COPPERMINE')) { die('Not in Coppermine...');} // Add plugin_install action $thisplugin->add_action('plugin_install','sef_urls_install'); // Add plugin_uninstall action $thisplugin->add_action('plugin_uninstall','sef_urls_uninstall'); // Add plugin_configure action $thisplugin->add_action('plugin_configure','sef_urls_configure'); // Add plugin_cleanup action $thisplugin->add_action('plugin_cleanup','sef_urls_cleanup'); // Add page_html filter $thisplugin->add_filter('page_html','sef_urls_convert'); /** * 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 thumnails.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); // Rewrite thumnails.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] 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?album=[album] URLs to displayimage-[album].html $html = preg_replace('/displayimage\.php\?pos=([\-0-9]+)/i','displayimage-$1.html',$html); // Return modified HTML return $html; } /** * Configure plugin for install */ function sef_urls_configure($action) { global $thisplugin; if ($action===1) { $code = implode('',file($thisplugin->fullpath.'/ht.txt')); echo <<< EOT
EOT; } } /** * Display cleanup options for uninstall */ function sef_urls_cleanup($action) { if ($action===1) { echo <<< EOT EOT; } } /** * Install the plugin */ function sef_urls_install() { global $thisplugin; $create = @$_POST['create']; // There's no .htaccess file or user has clicked 'yes' on the create form if (!file_exists('.htaccess') || $create) { copy($thisplugin->fullpath.'/ht.txt','.htaccess'); return true; // An htaccess file exists; display the configure form } elseif (!isset($create)) { return 1; // User has clicked 'no' on the configure form. Install plugin. Don't create .htaccess file } else { return true; } } /** * Uninstall the plugin */ function sef_urls_uninstall() { global $thisplugin; $delete = @$_POST['delete']; // There's an .htaccess file and user has clicked 'yes' on the cleanup form; delete the .htaccess file if (file_exists('.htaccess') && $delete) { unlink('.htaccess'); return true; // An .htaccess file exists; display the cleanup form } elseif (file_exists('.htaccess') && !isset($delete)) { return 1; // User has clicked 'no' on the cleanup form. Uninstall plugin. Don't delete '.htaccess' file } else { return true; } } ?>