Foros del Web » Creando para Internet » Sistemas de gestión de contenidos »

mod_rewrite2 para cutenews 1.4.5

Estas en el tema de mod_rewrite2 para cutenews 1.4.5 en el foro de Sistemas de gestión de contenidos en Foros del Web. hola que tal a todos... bueno les cuento que alle un mod_rewrite para el cutenews que solo funciona para la versin 1.4.5, pero no puedo ...
  #1 (permalink)  
Antiguo 05/09/2009, 14:04
 
Fecha de Ingreso: agosto-2009
Mensajes: 292
Antigüedad: 14 años, 7 meses
Puntos: 5
mod_rewrite2 para cutenews 1.4.5

hola que tal a todos... bueno les cuento que alle un mod_rewrite para el cutenews que solo funciona para la versin 1.4.5, pero no puedo instalarlo... aqui les dejo el codigo haber si me lo pueden explicar se los agradeceria mucho

Código:
1. Go to the directory which contains the file showing your news (let's call this file news.php). 
If you already have a .htaccess file in this directory - delete it. 
Make sure this directory is writable as the hack will automatically create a new .htaccess file. 

2. Open news.php (file which shows your news) and find your include code:
For example:

#############################
$category = 2;
$number = 10;
$template = "Headlines";
include("cute/show_news.php");
#############################



3. Put this ABOVE your include code:
(You may change $path_to_data to point to your cutenews/data folder.)

#############################
//Mod_rewrite start
ob_start();

$path_to_data = "./data";

$url = $_GET['url'];
$test = find_archive(title_to_id($url));
$id = title_to_id($url);
$ucat = title_to_ucat($url);

//Mod_rewrite end
#############################



4. Put this BELOW your include code:
(You may change this line in the function below: $letter_replacements = array('ö' => 'oe', 'ä' => 'ae'); to convert certain characters of your language.)

#############################

//Mod_rewrite start

function replace_title($title){
$letter_replacements = array('ö' => 'oe', 'ä' => 'ae');
	$result = strtolower(strip_tags(html_entity_decode($title)));
	$result = strtr($result, $letter_replacements);
	$result = preg_replace('/\W/', "-", strip_tags($result));
	
	return $result;
}

function title_to_id($title){
global $path_to_data;

	if($handle = opendir($path_to_data."/archives"))
		while (false !== ($file = readdir($handle))){
			if($file != "." and $file != ".." and eregi("news", $file)){
				$files_arch[] = $path_to_data."/archives/$file";
			}
		}
	$files_arch[] = $path_to_data."/news.txt";

foreach($files_arch as $file){
	$all_news = file($file);
	foreach($all_news as $news_line){
		$news_arr = explode("|", $news_line);
		if(replace_title($news_arr[2]) == $title){

			return $news_arr[0];
		}
	}
}
}

function title_to_ucat($title){
global $path_to_data;
	$all_news = file($path_to_data."/news.txt");
	foreach($all_news as $news_line){
		$news_arr = explode("|", $news_line);
		if(replace_title($news_arr[2]) == $title){
			return $news_arr[6];
		}
	}
}

function find_archive($id){
global $path_to_data;

	if($handle = opendir($path_to_data."/archives"))
		while (false !== ($file = readdir($handle))){
			if($file != "." and $file != ".." and eregi("news", $file)){
				$files_arch[] = $path_to_data."/archives/$file";
			}
		}
	$files_arch[] = $path_to_data."/news.txt";

	foreach($files_arch as $file){
		$all_news_db = file("$file");
		foreach($all_news_db as $news_line){
			$news_arr = explode("|", $news_line);
			if($news_arr[0] == $id){
				if(ereg("([[:digit:]]{0,})\.news\.arch", $file, $regs)){ $archive = $regs[1]; }
				return $archive;
			}
		}
	}
}

function id_to_title($id, $archiv = false, $type, $page = ''){
global $path_to_data;

	if($archiv){
	$all_news = file($path_to_data."/archives/".$archiv.".news.arch");
	}
	else{
	$all_news = file($path_to_data."/news.txt");
	}
		
	foreach($all_news as $news_line){
		$news_arr = explode("|", $news_line);
		if($news_arr[0] == $id){
			$title = replace_title($news_arr[2]);
			if($type == "commentspage"){
				return "commentspage/".$page."/".$title.".html";
			}
			else
			return $type."/".$title.".html";
		}
	}
}

$show_news = ob_get_contents();
ob_get_clean();

$script_file = end($script_url = explode("/", $HTTP_SERVER_VARS['SCRIPT_NAME']));
$path = substr($HTTP_SERVER_VARS['SCRIPT_NAME'], 0, -strlen($script_file));

$find = array(	/*post*/			"#".$script_file."\?subaction=showfull&id=(.*?)&archive=&start_from=&ucat=(.*?)&#ie",
				/*postcomments*/	"#".$script_file."\?subaction=showcomments&id=(.*?)&archive=&start_from=&ucat=(.*?)&#ie",
				/*postpage*/		"#".$script_file."\?start_from=(.*?)&ucat=&archive=&subaction=&id=(.*?)&#i",
				/*archiveindex*/	"#".$script_file."\?archive=(.*?)&subaction=list-archive#i",
				/*archive*/			"#".$script_file."\?subaction=showfull&id=(.*?)&archive=(.*?)&start_from=&ucat=(.*?)&#ie",
				/*archivepage*/		"#".$script_file."\?start_from=(.*?)&ucat=&archive=(.*?)&subaction=list-archive&id=&#i",
				/*archivecomments*/	"#".$script_file."\?subaction=showcomments&id=(.*?)&archive=(.*?)&start_from=&ucat=(.*)&#ie",
				/*searchnews*/		"#".$script_file."\?misc=search&subaction=showfull&id=(.*?)&archive=&cnshow=news&ucat=(.*?)&start_from=&#ie",
				/*searcharchives*/	"#".$script_file."\?misc=search&subaction=showfull&id=(.*?)&archive=(.*?)&cnshow=news&ucat=(.*?)&start_from=&#ie",
				/*ncommentspage*/	"#".$script_file."\?comm_start_from=(.*?)&archive=&subaction=showcomments&id=(.*?)&ucat=(.*?)&#ie",
				/*acommentspage*/	"#".$script_file."\?comm_start_from=(.*?)&archive=(.*?)&subaction=showcomments&id=(.*?)&ucat=(.*?)&#ie",
			);

$replace = array(	"id_to_title('\\1', false, 'post')",
					"id_to_title('\\1', false, 'comments')",
					"postpage/\\1.html",
					"archiveindex/\\1.html",
					"id_to_title('\\1', '\\2', 'archive')",
					"archivepage/\\2/\\1.html",
					"id_to_title('\\1', '\\2', 'comments')",
					"id_to_title('\\1', false, 'post')",
					"id_to_title('\\1', '\\2', 'archive')",
					"id_to_title('\\2', false, 'commentspage', '\\1')",
					"id_to_title('\\3', '\\2', 'commentspage', '\\1')",
				);

$show_news = preg_replace($find, $replace, $show_news);
$show_news = str_replace("&url=".$url, '', $show_news);

if(!file_exists('.htaccess')){
$htaccess = "RewriteEngine On\n";
$htaccess .= "RewriteBase ".$path."\n\n";
$htaccess .= "RewriteRule ^post/(.*).html(.*)$ ".$script_file."?subaction=showfull&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^postpage/(.*).html(.*)$ ".$script_file."?start_from=$1$2 [L,NC]\n\n";
$htaccess .= "RewriteRule ^comments/(.*).html(.*)$ ".$script_file."?subaction=showcomments&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^commentspage/(.*)/(.*).html(.*)$ ".$script_file."?comm_start_from=$1&subaction=showcomments&url=$2$3 [L,NC]\n\n";
$htaccess .= "RewriteRule ^archiveindex/(.*).html(.*)$ ".$script_file."?archive=$1&subaction=list-archive$2 [L,NC]\n";
$htaccess .= "RewriteRule ^archive/(.*).html(.*)$ ".$script_file."?subaction=showfull&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^archivepage/(.*)/(.*).html(.*)$ ".$script_file."?start_from=$2&archive=$1&subaction=list-archive$3 [L,NC]";

$file = fopen(".htaccess", "w");
fwrite($file, $htaccess);
fclose($file);
}

echo $show_news;
//Mod_rewrite end

######################################



5. Open show_archives.php and find this:
######################################
error_reporting (E_ALL ^ E_NOTICE);
######################################

add below:
######################################
//Mod rewrite
if($test != '') $archive = $test;
//Mod rewrite
######################################



6. Open show_news.php and find this:
######################################
error_reporting (E_ALL ^ E_NOTICE);
######################################

add below:
######################################
//Mod rewrite
if($test != '') $archive = $test;
//Mod rewrite
######################################



7. Open inc/shows.inc.php and find this:
######################################
echo "<script type=\"text/javascript\">window.location=\"$PHP_SELF?subaction=showfull&id=$id&ucat=$ucat&archive=$archive&start_from=$start_from&$user_query\";</script>";
######################################

replace with this:
######################################
echo "<script type=\"text/javascript\">window.location=\"$PHP_SELF\";</script>";
######################################


8. Open inc/shows.inc.php and find this:
######################################
$user_query = cute_query_string($QUERY_STRING, array( "comm_start_from","start_from", "archive", "subaction", "id", "ucat"));
######################################

add below:
######################################
if($user_query != "")
$user_query = "&".$user_query;
######################################
saludos y muchas gracias de antemano
  #2 (permalink)  
Antiguo 10/09/2009, 12:27
AlvaroG
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: mod_rewrite2 para cutenews 1.4.5

¿Qué es lo que no funciona? ¿has seguido los pasos tal cual te los explica el archivo?
  #3 (permalink)  
Antiguo 24/09/2009, 15:17
 
Fecha de Ingreso: agosto-2009
Mensajes: 292
Antigüedad: 14 años, 7 meses
Puntos: 5
Respuesta: mod_rewrite2 para cutenews 1.4.5

hola que tal ya pude hacer que sa cambiaran las url a amigales, pero ahora tengo otro problema, cuando kiero agregar un comentario o ver la noticia completa me sale que la url no existe ,,, pueden mirar aqui xboxnetwork.co.cc/

el problema era que tenia que poner el $path_to_data completo /home/vol**/*********/*************/xboxnetwork.co.cc/******/noticias

Última edición por WinderJerter; 24/09/2009 a las 17:12 Razón: solucionado!!!
  #4 (permalink)  
Antiguo 25/09/2009, 18:49
 
Fecha de Ingreso: agosto-2009
Mensajes: 292
Antigüedad: 14 años, 7 meses
Puntos: 5
Pregunta Respuesta: mod_rewrite2 para cutenews 1.4.5

Hola amigos que tal andan,,, bueno como puse en el comentario anterior ya resolvi la duda que tenia y para no abrir un nuevo tema que palteo aqui:

Lo que pasa esque ando quiero que la url del paginador de noticias que esta asi al url: xboxnetwork.co.cc/comments-pag/2/hola.html

Primero: pagina de los comentarios.
Segundo: numero de pagina de los comentarios.
Tercero: titulo de la noticia que se esta comentando.

y como yo kiero que queda la url es asi: xboxnetwork.co.cc/hola/comments-pag/2.html

Primero: titulo de la noticia que se esta comentando.
Segundo: pagina de los comentarios.
tercero: numero de pagina de los comentarios.

He estado modificando el codigo .htaccess para ver si lo podia cambiar como los demas links pero no sirvio en este , este el codigo:

Código:
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)/post.html(.*)$ index.php?subaction=showfull&url=$1$2 [L,NC]
RewriteRule ^pag/(.*).html(.*)$ index.php?start_from=$1$2 [L,NC]

RewriteRule ^(.*)/comments.html(.*)$ index.php?subaction=showcomments&url=$1$2 [L,NC]
RewriteRule ^comments-pag/(.*)/(.*).html(.*)$ index.php?comm_start_from=$1&subaction=showcomments&url=$2$3 [L,NC]

RewriteRule ^archiveindex/(.*).html(.*)$ index.php?archive=$1&subaction=list-archive$2 [L,NC]
RewriteRule ^archive/(.*).html(.*)$ index.php?subaction=showfull&url=$1$2 [L,NC]
RewriteRule ^archivepage/(.*)/(.*).html(.*)$ index.php?start_from=$2&archive=$1&subaction=list-archive$3 [L,NC]

ErrorDocument 403 /403
ErrorDocument 404 /404
y tambien tengo que modificar el archivo php pero no se donde le tengo que cambiar, codigo php:

Código PHP:
<?PHP

//Mod_rewrite start
ob_start();

$path_to_data "/home/vol1/byethost10.com/b10_2348819/xboxnetwork.co.cc/htdocs/noticias/data";

$url $_GET['url'];
$test find_archive(title_to_id($url));
$id title_to_id($url);
$ucat title_to_ucat($url);

//Mod_rewrite end

$number=2;
include(
"/home/vol1/byethost10.com/b10_2348819/xboxnetwork.co.cc/htdocs/noticias/show_news.php");

//Mod_rewrite start

function replace_title($title){
$letter_replacements = array('ö' => 'oe''ä' => 'ae');
$result strtolower(strip_tags(html_entity_decode($title)));
$result strtr($result$letter_replacements);
$result preg_replace('/\W/'"-"strip_tags($result));

return 
$result;
}

function 
title_to_id($title){
global 
$path_to_data;

if(
$handle opendir($path_to_data."/archives"))
while (
false !== ($file readdir($handle))){
if(
$file != "." and $file != ".." and eregi("news"$file)){
$files_arch[] = $path_to_data."/archives/$file";
}
}
$files_arch[] = $path_to_data."/news.txt";

foreach(
$files_arch as $file){
$all_news file($file);
foreach(
$all_news as $news_line){
$news_arr explode("|"$news_line);
if(
replace_title($news_arr[2]) == $title){

return 
$news_arr[0];
}
}
}
}

function 
title_to_ucat($title){
global 
$path_to_data;
$all_news file($path_to_data."/news.txt");
foreach(
$all_news as $news_line){
$news_arr explode("|"$news_line);
if(
replace_title($news_arr[2]) == $title){
return 
$news_arr[6];
}
}
}

function 
find_archive($id){
global 
$path_to_data;

if(
$handle opendir($path_to_data."/archives"))
while (
false !== ($file readdir($handle))){
if(
$file != "." and $file != ".." and eregi("news"$file)){
$files_arch[] = $path_to_data."/archives/$file";
}
}
$files_arch[] = $path_to_data."/news.txt";

foreach(
$files_arch as $file){
$all_news_db file("$file");
foreach(
$all_news_db as $news_line){
$news_arr explode("|"$news_line);
if(
$news_arr[0] == $id){
if(
ereg("([[:digit:]]{0,})\.news\.arch"$file$regs)){ $archive $regs[1]; }
return 
$archive;
}
}
}
}

function 
id_to_title($id$archiv false$type$page ''){
global 
$path_to_data;

if(
$archiv){
$all_news file($path_to_data."/archives/".$archiv.".news.arch");
}
else{
$all_news file($path_to_data."/news.txt");
}

foreach(
$all_news as $news_line){
$news_arr explode("|"$news_line);
if(
$news_arr[0] == $id){
$title replace_title($news_arr[2]);
if(
$type == "comments-pag"){
return 
"comments-pag/".$page."/".$title.".html";
}
else
return 
$title."/".$type.".html";
}
}
}

$show_news ob_get_contents();
ob_get_clean();

$script_file end($script_url explode("/"$HTTP_SERVER_VARS['SCRIPT_NAME']));
$path substr($HTTP_SERVER_VARS['SCRIPT_NAME'], 0, -strlen($script_file));

$find = array( /*post*/ "#".$script_file."\?subaction=showfull&amp;id=(.*?)&amp;archive=&amp;start_from=&amp;ucat=(.*?)&amp;#ie",
/*postcomments*/ "#".$script_file."\?subaction=showcomments&amp;id=(.*?)&amp;archive=&amp;start_from=&amp;ucat=(.*?)&amp;#ie",
/*postpage*/ "#".$script_file."\?start_from=(.*?)&amp;ucat=&amp;archive=&amp;subaction=&amp;id=(.*?)&amp;#i",
/*archiveindex*/ "#".$script_file."\?archive=(.*?)&subaction=list-archive#i",
/*archive*/ "#".$script_file."\?subaction=showfull&amp;id=(.*?)&amp;archive=(.*?)&amp;start_from=&amp;ucat=(.*?)&amp;#ie",
/*archivepage*/ "#".$script_file."\?start_from=(.*?)&amp;ucat=&amp;archive=(.*?)&amp;subaction=list-archive&amp;id=&amp;#i",
/*archivecomments*/ "#".$script_file."\?subaction=showcomments&amp;id=(.*?)&amp;archive=(.*?)&amp;start_from=&amp;ucat=(.*)&amp;#ie",
/*searchnews*/ "#".$script_file."\?misc=search&subaction=showfull&id=(.*?)&archive=&cnshow=news&ucat=(.*?)&start_from=&#ie",
/*searcharchives*/ "#".$script_file."\?misc=search&subaction=showfull&id=(.*?)&archive=(.*?)&cnshow=news&ucat=(.*?)&start_from=&#ie",
/*ncommentspage*/ "#".$script_file."\?comm_start_from=(.*?)&amp;archive=&amp;subaction=showcomments&amp;id=(.*?)&amp;ucat=(.*?)&amp;#ie",
/*acommentspage*/ "#".$script_file."\?comm_start_from=(.*?)&amp;archive=(.*?)&amp;subaction=showcomments&amp;id=(.*?)&amp;ucat=(.*?)&amp;#ie",
);

$replace = array( "id_to_title('\\1', false, 'post')",
"id_to_title('\\1', false, 'comments')",
"pag/\\1.html",
"archiveindex/\\1.html",
"id_to_title('\\1', '\\2', 'archive')",
"archivepage/\\2/\\1.html",
"id_to_title('\\1', '\\2', 'comments')",
"id_to_title('\\1', false, 'post')",
"id_to_title('\\1', '\\2', 'archive')",
"id_to_title('\\2', false, 'comments-pag', '\\1')",
"id_to_title('\\3', '\\2', 'comments-pag', '\\1')",
);

$show_news preg_replace($find$replace$show_news);
$show_news str_replace("&url=".$url''$show_news);

if(!
file_exists('.htaccess')){
$htaccess "RewriteEngine On\n";
$htaccess .= "RewriteBase ".$path."\n\n";
$htaccess .= "RewriteRule ^(.*)/post.html(.*)$ ".$script_file."?subaction=showfull&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^pag/(.*).html(.*)$ ".$script_file."?start_from=$1$2 [L,NC]\n\n";
$htaccess .= "RewriteRule ^(.*)/comments.html(.*)$ ".$script_file."?subaction=showcomments&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^comments-pag/(.*)/(.*).html(.*)$ ".$script_file."?comm_start_from=$1&subaction=showcomments&url=$2$3 [L,NC]\n\n";
$htaccess .= "RewriteRule ^archiveindex/(.*).html(.*)$ ".$script_file."?archive=$1&subaction=list-archive$2 [L,NC]\n";
$htaccess .= "RewriteRule ^archive/(.*).html(.*)$ ".$script_file."?subaction=showfull&url=$1$2 [L,NC]\n";
$htaccess .= "RewriteRule ^archivepage/(.*)/(.*).html(.*)$ ".$script_file."?start_from=$2&archive=$1&subaction=list-archive$3 [L,NC]";

$file fopen(".htaccess""w");
fwrite($file$htaccess);
fclose($file);
}

echo 
$show_news;
//Mod_rewrite end

?>
Según yo tengo que cambiar de orden la linea:

return "comments-pag/".$page."/".$title.".html";

la cual la cambio y me da un error en el cutenews y tambien hay esta lineas:

"id_to_title('\\2', false, 'comments-pag', '\\1')",
"id_to_title('\\3', '\\2', 'comments-pag', '\\1')",

que yo pienso que tambien les tengo de modificar algo pero no se...

espero que me puedan ayudar a resolver mi problema, se los agradeceria muchicimo,,, saludos

EDIT: se me olvidaba una cosa mas... como le puedo hacer para que las noticias esten en una carpeta por ejemplo asi, porque tengo el archivo que muestra las noticias en la carpeta ese pero las muestra en el index... talves sea por el .htaccess??? y la otra cosa que quiero es que cuando publiquen un comentario no te mande al index sino hay mismo gracias

xboxnetwork.co.cc/noticias/hola/post.html

Última edición por WinderJerter; 25/09/2009 a las 20:37
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:45.