Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/01/2003, 19:28
Avatar de ORPHEO
ORPHEO
 
Fecha de Ingreso: diciembre-2002
Mensajes: 77
Antigüedad: 21 años, 4 meses
Puntos: 0
Pregunta Otra vez upload (esta vez texto).

Hola de nuevo:

Otra vez vuelvo a por ayuda...

He creado una página de relatos con la posibilidad de que mis visitantes suban sus propios relatos (http://www.sexoparamo.com/relatos/relatos.php).

Consta de varios scripts que conseguí en http://php.resourceindex.com/Complete_Scripts/


- relatos.php : Es la página principal, en ella llamo al sumario de relatos con <? include("article_summary.php"); ?>

- config.php : Archivo de configuración básica

- t_summary.php : Template del sumario de relatos

- t_article.php : Template de la página de relato

- latest.php : Últimos n relatos subidos

- news.php : Subir relatos

- template.inc : PHPLib template library

- article_(article_id_here).php : Página de relato único(script will - create these files)

- article_summary.php : Lista de relatos subidos(script will create this file).


Códigos:

- config.php
Código PHP:
<?

 $summary_template 
"t_summary.php";

 
$article_template "t_article.php";

 
$max_summary 4;

 
$max_latest 3;  

 
$password "test";

?>
- t_summary.php
Código PHP:
<p>
<
b><a href={article_url}>{subject}</a></b>
<
br>
<
font size=1>{date}</font>
<
p>
{
summary}
<
p
- t_article.php
Código PHP:
<p>
<
b>{subject}</b>
<
br>
<
font size=1>{date}</font>
<
p>
{
body}
<
p
- latest.php
Código PHP:
<?

        
require('config.php'); 

    
$filename "article_summary.php";

    
#- open article summaries
    
if(file_exists($filename)){
        
$fh fopen($filename"r");
        
$old_news fread($fhfilesize($filename));
        
fclose($fh);
    }

 
    
#- get first five article
    
$articles explode("<!--ARTICLE-->"$old_news);

    
$i=0;
    foreach ( 
$articles as $article ){
        if(
count($articles)>$i){
            if(
$max_latest >= $i++){
                print 
$article;
            }
        }
    }

?>
- news.php
Código PHP:
<html>
<body bgcolor=yellow>

<basefont size=2 face=arial>

<b>Add Article</b>
<?
        
include ("template.inc");
        include (
"config.php");

    
$summary_template "t_summary.php";
    
$article_template "t_article.php";
    
$max_summary 5;

    function 
summary_page ($subject$date$summary$article_id)
    {
        global 
$summary_template;
            
$t = new Template();
            
$t->set_file("SummaryPage"$summary_template);
        
$article_url "article_".$article_id.".php";
        
$date nl2br($date);
        
$summary =  nl2br($summary);     
        
$t->set_var( array(
                
"subject" => $subject,
                
"date"    => $date,
                
"summary" => $summary,
                
"article_url" => $article_url
                
));
        
$t->parse("Summary""SummaryPage");
        return 
$t->get_var("Summary");
    }

    function 
main_page ($subject$date$summary$article_id$body)
    {
        global 
$article_template;

                
$t = new Template();
                
$t->set_file("ArticlePage"$article_template);
                
$article_url "article_".$article_id.".php";
                
$date nl2br($date);
                
$summary =  nl2br($summary);
                
$body =  nl2br($body);
                
$t->set_var( array(
                                
"subject" => $subject,
                                
"date"    => $date,
                                
"summary" => $summary,
                                
"body" => $body,
                                
"article_url" => $article_url
                                
));
                
$t->parse("Article""ArticlePage");
                return 
$t->get_var("Article"); 
    }

    function 
add_article($filename$news)
    {

        if(
file_exists($filename)){
            
$fh fopen($filename"r");
            
$old_news fread($fhfilesize($filename));
            
fclose($fh); 
        }

        
/* TODO: Multipage articles
            preg_match_all("<!--ARTICLE PAGE=(\d*)-->", $old_news, $matches;
        
            if( count($matches[0]) >= $max_summary){
                $oldfilename = $filename.($matches[0][0]+1);
            } 
        */

        
$fh fopen($filename"w");
        
$news stripslashes($news);
        
fwrite($fh"\n<!--ARTICLE-->\n$news $old_news");
        
fclose($fh);
    }

?>

<?
    
if(strcmp($subject"")){    
        if(!(
strcmp($passwd$password))){    
            
add_article("article_summary.html"summary_page($subject$date$summary$article_id));
            
add_article("article_$article_id.html"main_page($subject$date$summary$article_id$body));
            echo 
"<p> Article has been added! <p>";
        }else{
            echo 
"<p><b> Password is wrong! </b>";
        }
    }
?>


<form action=news.php method=post>
<table border=0>
<tr> <td> (Password): </td><td> <input type=text name=passwd size=30> </td></tr>
<tr> <td> Subject: </td><td> <input type=text name=subject size=30> </td></tr>
<tr> <td> Article ID: </td><td> <input type=text name=article_id value=<? echo date("Y_m_j_is"); ?> size=30> </td></tr>
<tr> <td> Date/Author/etc: </td><td> <textarea name=date rows=2 cols=30 wrap=soft><? echo date("M j, Y\n"); ?>Author: </textarea> </td></tr>
<tr> <td> Summary: </td><td> <textarea name=summary rows=5 cols=30 wrap=soft></textarea> </td></tr>
<tr> <td> Body: </td><td> <textarea name=body rows=15 cols=30></textarea> </td></tr>
</table>
<input type=submit name=submit value=Add>
</form>
El template.inc no lo incluyo aquí (no creo que sea necesario...).

Pues bien, el único problema es que no me crea varias páginas cuando el número de relatos excede del que yo le marco en config.php.

Creo que el error está en news.php. He cambiado
Código PHP:
        /* TODO: Multipage articles
            preg_match_all("<!--ARTICLE PAGE=(\d*)-->", $old_news, $matches;
        
            if( count($matches[0]) >= $max_summary){
                $oldfilename = $filename.($matches[0][0]+1);
            } 
        */ 
por esto
Código PHP:
        // TODO: Multipage articles
            
preg_match_all("<!--ARTICLE PAGE=(\d*)-->"$old_news$matches;
        
            if( 
count($matches[0]) >= $max_summary){
                
$oldfilename $filename.($matches[0][0]+1);
            } 
pero sigue sin funcionar. Podéis ayudarme?

Salu2.
__________________
http://www.sexoparamo.com

Última edición por ORPHEO; 22/01/2003 a las 11:28