Foros del Web » Programando para Internet » PHP »

PHP OO Tengo un problem con el sistema de noticias sin db

Estas en el tema de Tengo un problem con el sistema de noticias sin db en el foro de PHP en Foros del Web. Hola muy buenas! Aquí les dejo un sistema de noticias que lo quiero usar como cms... pero lo que no han hecho en este script ...
  #1 (permalink)  
Antiguo 16/08/2011, 09:39
Avatar de carlosmderio3  
Fecha de Ingreso: marzo-2011
Ubicación: valencia
Mensajes: 67
Antigüedad: 13 años, 1 mes
Puntos: 0
Exclamación Tengo un problem con el sistema de noticias sin db

Hola muy buenas!
Aquí les dejo un sistema de noticias que lo quiero usar como cms...
pero lo que no han hecho en este script e poder borrar los archivos ( las noticias creadas en archivos .txt en la capeta /news en mi servidor local si lo hace pero no mediante FTP y lo que me gustaria es que alguien me heche un cable por que estoy muy perdido, estuve googleando muy mucho y no encuentro solucion al menos que me puedan acesorar de como hacer este mismo script mediante base de datos.

ya no se por donde mas tirar... he intentado muy mucho y mis conocimientos se han quedado estancados ya....


crear capeta news

maxNews.class.php

Código PHP:
<?php
class maxNews{
   var 
$newsDir 'news';
   var 
$newsList;
   var 
$newsCount 1;
   
//var $newsCount = -1;
function getNewsList(){
    
   
$this->newsList = array();
   
    
// Open the actual directory
    
if ($handle = @opendir($this->newsDir)) {
        
// Read all file from the actual directory
        
while ($file readdir($handle))  {
            if (!
is_dir($file)) {
               
$this->newsList[] = $file;
          }
        }
    }    
    
    
rsort($this->newsList);
    
    return 
$this->newsList;
}   

function 
getNewsCount(){
   if (
$this->newsCount == -1$this->getNewsList();
   
$this->newsCount sizeof($this->newsList);
   return 
$this->newsCount;
}

function 
displayNews(){
      
$list $this->getNewsList();
      
      echo 
"<table class='newsList'>";
      foreach (
$list as $value) {
          
$newsData file($this->newsDir.DIRECTORY_SEPARATOR.$value);
          
$newsTitle  $newsData[0];
         
$submitDate $newsData[1];    
         unset (
$newsData['0']);
         unset (
$newsData['1']);
          
         
$newsContent "";
         foreach (
$newsData as $value) {
               
$newsContent .= $value;
         }
          
          echo 
"<tr><th align='left'>$newsTitle</th>
                    <th class='right'>$submitDate</th></tr>"
;
          echo 
"<tr><td colspan='2'>".$newsContent."<br/></td></tr>";
      }
      echo 
"</table>";
      if (
sizeof($list) == 0){
         echo 
"<center><p>No hay noticias en este momento!</p><p>&nbsp;</p></center>";
      }
}

function 
displayAddForm(){
?>  
   <script language="javascript" type="text/javascript" src="js/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_align : "center",
    theme_advanced_toolbar_location : "top",

});
</script>  
  <form class="iform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Titulo:<br/>
    <input type="text" name="title" size="40"/> 
     Tu nombre&nbsp;
     <input name="name" type="text" id="name" value="<?php echo $_SESSION['username']; ?>" readonly="readonly"><br/>
     
    <br/>
    Contentario:<br/>
    <textarea name="newstext" rows="15" cols="67"></textarea><br/>
    <center><input type="submit" name="submit" value="Enviar comentario" /></center>
  </form> 
   
<?php   
}

function 
insertNews(){
   
$newsTitel   = isset($_POST['title']) ? $_POST['title'] : 'Untitled';
  
// $submitDate  = date('Y-m-d g:i:s A');
   
$newsContent = isset($_POST['newstext']) ? $_POST['newstext'] : 'No content';
    
$submitDate   = isset($_POST['name']) ? $_POST['name'] : 'Untitled';
   
   
$filename date('j.m.Y-.H.i.s');
   if (!
file_exists($this->newsDir)){
      
mkdir($this->newsDir);
   }
   
$f fopen($this->newsDir.DIRECTORY_SEPARATOR.$filename.".txt","w+");         
   
fwrite($f,$newsTitel."\n");
    
fwrite($f,$submitDate."\n");
 
//  fwrite($f,$submitDate."\n");
   
fwrite($f,$newsContent."\n");
   
fclose($f);

   
header('Location:index.php?id=eventos');   
   
}
}
?>
Admin.php // aqui escribes las noticias


Código PHP:
<?php
require_once("maxNews.class.php"); 
$newsHandler = new maxNews();  
if (!isset(
$_POST['submit'])) {
?>
<html>
<head>
bla bla bla
</head>
<body>
bla bla bla

Código PHP:
<?
$newsHandler
->displayAddForm(); 
$newsHandler->displayNews();
 }
?>
Bla bla bla

Código PHP:
<?php 
} else {
   
$newsHandler->insertNews();
}
?>
</body>
</html>

Index.php //lector de noticias.

Código PHP:
<?php 
   
require_once("maxNews.class.php"); 
   
$newsHandler = new maxNews();          
?>
<html>
bla bla bla...

<body>

// lee todo lo escrito

Código PHP:
<div id="current">
         <? $newsHandler->displayNews(); ?>
    </div>
bla bla
</html>
__________________
Oir EuropaFM Valencia!
  #2 (permalink)  
Antiguo 16/08/2011, 16:17
 
Fecha de Ingreso: febrero-2010
Mensajes: 818
Antigüedad: 14 años, 2 meses
Puntos: 55
Respuesta: Tengo un problem con el sistema de noticias sin db

mi no entender
Código PHP:
function borrar($ruta){
 if(
unlink($ruta)){
  return 
true;
}
else{return 
false;}


Etiquetas: ftp, sistema-administracion, sistema-noticias
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 23:48.