Script di aggiornamento news

  • Creatore Discussione Creatore Discussione Seraph
  • Data di inizio Data di inizio

Seraph

Nuovo Utente
12 Ott 2005
3
0
0
Salve a tutti,

ho scaricato uno script di gestione news (Digi News) in php (non necessita di db) che mi sta creando non pochi problemi. E' tutto installato in una cartella unica, senza sottodirectory. In locale funziona tutto bene, ma quando vado ad uploadare sull'host non funziona una benemerita. Cioè se da locale inserisco una nuova news o modifico va benissimo, dall'host invece appena faccio uno dei due passaggi sopracitati non fa niente, non aggiunge e non modifica:

allora, lo script è basato su 4 file:

admin.php

<?php
$digiNewsPath = './store/news.dat';
require './news.inc.php';

if ($action == 'auth') {
auth();
}
if (($HTTP_COOKIE_VARS['user'] != $digiNews['user']) && ($HTTP_COOKIE_VARS['pass'] != $digiNews['pass'])) {
login();
exit;
}
if ($action == 'config') {
config();
} else if ($action == 'list') {
view();
} else if ($action == 'edit') {
edit();
} else if ($action == 'add') {
add();
} else if ($action == 'logout') {
logout();
} else {
menu();
}
function head($title)
{
echo '<html><head><title>Gestione News ' .$title. '</title></head><body bgcolor=#ffffff><center><font face="Verdana, Helvetica" size=+3>Gestione News</font><br><font face="Verdana, Helvetica" size=2><b>' .$title. '</b></font><p><table width=550 border=0 cellspacing=2 cellpadding=2><tr><td>';
}
function foot()
{
echo '</td></tr></table></center><p><center><hr width=550><font face="Verdana, Helvetica" size=1><a href=admin.php?action=config>Gestione</a> | <a href=admin.php?action=list>Tutte le news</a> | <a href=admin.php?action=add>Aggiungi una news</a> | <a href=admin.php?action=logout>Logout</a></font></center></body></html>';
}
function auth()
{
global $user, $pass, $digiNews;
if (($user != $digiNews['user']) || ($pass != $digiNews['pass'])) {
login('Username o password errate');
exit;
}
setcookie('user', $user);
setcookie('pass', $pass);
menu();
}
function login($msg = '')
{
head('Richiesta autorizzazione');
if ($msg != '') {
echo '<font face="Verdana, Helvetica" color=#ff000 size=2><b>' .$msg. '</b></font><p>';
}
echo '<font face="Verdana, Helvetica" size=2>Devi effettuare il login per poter accedere al pannello di controllo. Inserire il login e la password nelle form sottostanti. ATTENZIONE: i cookies devono essere abilitati nel vostro browser.</font><br><br><form method=post action=admin.php><input type=hidden name=action value=auth><font face="Verdana, Helvetica" size=2><b>USERNAME:<br></b></font> <input type=text name=user><br><font face="Verdana, Helvetica" size=2><b><br><br>PASSWORD:<br></b></font> <input type=password name=pass><br><br><br><input type=submit value=Login></form>';
foot();
}
function menu()
{
head('Menu');
echo '<font face="Verdana, Helvetica" size=2>Se è il primo accesso al pannello di controllo, si prega di scegliere la configurazione desierata, altrimenti si possono eseguire le seguenti operazioni:<ul><li><a href=admin.php?action=config>Configurazione</a></li><li><a href=admin.php?action=list>Lista delle news</a></li><li><a href=admin.php?action=add>Aggiungi una news</a></li><li><a href=admin.php?action=logout>Logout</a></li></ul>';
foot();
exit;
}
function config()
{
global $save, $cancel, $newlogin, $newpass, $template, $toffset, $tformat, $digiNews;
if ($save) {
$digiNews['user'] = $newlogin;
if ($newpass != '**********') {
$digiNews['pass'] = $newpass;
}
$digiNews['template'] = $template;
$digiNews['toffset'] = $toffset;
$digiNews['tformat'] = $tformat;
writenews();
menu();
} else if ($cancel) {
menu();
} else {
head('Configurazione');
echo '<font face="Verdana, Helvetica" size=2>Si possono modificare le seguenti proprietà. Attenzione a non modificare il file NEWS.DAT </font><hr width=550><form method=post action=admin.php><input type=hidden name=action value=config><font face="Verdana, Helvetica" size=2><li><b>Login e Password</b></li><p>da qui si possono cambiare lo username e la password</font><p><font face="Verdana, Helvetica" size=2>Username:</font> <input type=text name=newlogin value="' .$digiNews['user']. '"><br><font face="Verdana, Helvetica" size=2>Password:</font> <input type=password name=newpass value="**********"><hr width=550><font face="Verdana, Helvetica" size=2><li><b>Indirizzo Template</b></li><p>Indirizzo url per il file template</font><p><font face="Verdana, Helvetica" size=2>Indirizzo del template:</font> <input type=text name=template value="' .$digiNews['template']. '"><hr width=550><font face="Verdana, Helvetica" size=2><li><b>Tempo</b></li><p>NON MODIFICARE</font><p><font face="Verdana, Helvetica" size=2>Timezone </font> <input type=text name=toffset value="' .$digiNews['toffset']. '" size=4><hr width=550><font face="Verdana, Helvetica" size=2><li><b>Formato della data</b></li><p>NON MODIFICARE</font><p><font face="Verdana, Helvetica" size=2>Formato della data:</font> <input type=text name=tformat value="' .$digiNews['tformat']. '"><p><input type=submit name=save value=Save> <input type=submit name=cancel value=Cancel>';
foot();
}
}
function view()
{
global $news;
head('Tutte le news');
echo '<table border=1 cellspacing=0 cellpadding=1><tr><td nowrap><font face="Verdana, Helvetica" size=1><b>Oggetto (ID):</b></font></td><td><font face="Verdana, Helvetica" size=1><b>Autore:</b></font></td><td><font face="Verdana, Helvetica" size=1><b>E-mail:</b></font></td><td><font face="Verdana, Helvetica" size=1><b>Testo:</b></font></td></tr>';
foreach ($news as $entry) {
$data = explode('||', $entry);
echo "<tr><td><font face=\"Verdana, Helvetica\" size=1><a href=admin.php?action=edit&id=$data[0]>$data[4] ($data[0])</a></font></td><td><font face=\"Verdana, Helvetica\" size=1>$data[2]</td><td><font face=\"Verdana, Helvetica\" size=1><a href=mailto:$data[3]>$data[3]</a></td><td><font face=\"Verdana, Helvetica\" size=1>$data[5]</font></td></tr>";
}
echo '<table>';
foot();
}
function edit()
{
global $id, $save, $confirm_delete, $delete, $cancel, $news_author, $news_authoremail, $news_subject, $news_body, $news, $digiNewsTime;
if (!$id) {
die('Nessuna News specificata');
}
if ($save) {
$news_subject = trim($news_subject);
$news_author = trim($news_author);
$news_authoremail = trim($news_authoremail);
$news_body = trim($news_body);
$news_body = str_replace("\n", '<br>', $news_body);
for ($i = 0; $i < count($news); $i++) {
if(ereg("^$id||", $news[$i])) {
$data = explode('||', $news[$i]);
$data[1] = $digiNewsTime;
$data[2] = $news_author;
$data[3] = $news_authoremail;
$data[4] = $news_subject;
$data[5] = $news_body;
$news[$i] = join('||', $data);
break;
}
}
writenews();
menu();
} else if ($delete) {
if(!$confirm_delete == 1) {
die('Non hai confermato la cancellazione');
}
foreach ($news as $entry) {
if(!ereg("^$id||", $entry)) {
$nnews[] = $entry;
}
}
$news = $nnews;
writenews();
menu();
} else if ($cancel) {
menu();
} else {
foreach ($news as $entry) {
if(ereg("^$id||", $entry)) {
$data = explode('||', $entry);
break;
}
}
if (!$data) {
die("News ID $id non trovata");
}
$data[5] = str_replace('<br>', "\n", $data[5]);
head('Edit News');
echo '<font face="Verdana, Helvetica" size=2>Modifica della news ' .$id. ':</font><form method=post action=admin.php><input type=hidden name=action value=edit><input type=hidden name=id value=' .$id. '><table width=550 border=1 cellspacing=0 cellpadding=1><tr><td><font face="Verdana, Helvetica" size=2><b>Autore:</b></font></td><td><input type=text name=news_author value="' .$data[2]. '" size=30></td></tr><tr><td><font face="Verdana, Helvetica" size=2><b>E-mail:</b></font></td><td><input type=text name=news_authoremail value="' .$data[3]. '" size=30></td></tr><tr><td><font face="Verdana, Helvetica" size=2><b>Oggetto:</b></font></td><td><input type=text name=news_subject value="' .$data[4]. '" size=30></td></tr><tr><td valign=top><font face="Verdana, Helvetica" size=2><b>Testo:</b></font></td><td><textarea name=news_body rows=12 cols=52 wrap=virtual>' .$data[5]. '</textarea></td></tr></table><br><center><input type=submit name=save value=Save> <input type=submit name=cancel value=Cancel><p><input type=checkbox name=confirm_delete value=1> <font face="Verdana, Helvetica" size=2>Clicca per confermare la cancellazione</font><br><input type=submit name=delete value="Delete This News"></center></form>';
foot();
}
}
function add()
{
global $save, $cancel, $news_author, $news_authoremail, $news_subject, $news_body, $news, $digiNewsTime;
if ($save) {
$data[0] = 0;
foreach ($news as $entry) {
ereg("^([0-9]+)||", $entry, $j);
$j[0] = str_replace('||', '', $j[0]);
if ($j[0] > $data[0]) {
$data[0] = $j[0];
}
}
$news_subject = trim($news_subject);
$news_author = trim($news_author);
$news_authoremail = trim($news_authoremail);
$news_body = trim($news_body);
$news_body = str_replace("\n", '<br>', $news_body);
$data[0]++;
$data[1] = $digiNewsTime;
$data[2] = $news_author;
$data[3] = $news_authoremail;
$data[4] = $news_subject;
$data[5] = $news_body;
array_unshift($news, join('||', $data));
writenews();
menu();
} else if ($cancel) {
menu();
} else {
head('Aggiungi una news');
echo '<form method=post action=admin.php><input type=hidden name=action value=add><table width=550 border=1 cellspacing=0 cellpadding=1><tr><td><font face="Verdana, Helvetica" size=2><b>Autore:</b></font></td><td><input type=text name=news_author size=30></td></tr><tr><td><font face="Verdana, Helvetica" size=2><b>E-mail Autore:</b></font></td><td><input type=text name=news_authoremail size=30></td></tr><tr><td><font face="Verdana, Helvetica" size=2><b>Oggetto:</b></font></td><td><input type=text name=news_subject size=30></td></tr><tr><td valign=top><font face="Verdana, Helvetica" size=2><b>Testo:</b></font></td><td><textarea name=news_body rows=12 cols=52 wrap=virtual></textarea></td></tr></table><br><center><input type=submit name=save value=Save> <input type=submit name=cancel value=Cancel></center></form>';
foot();
}
}
function logout()
{
setcookie('user', '');
setcookie('pass', '');
head('Log Out');
echo '<font face="Verdana, Helvetica" size=2>Log Out avvenuto con successo. Clicca <a href=admin.php>qui</a> per effettuare il login nuovamente.</font>';
foot();
exit;
}
?>


news.dat

1||1142815042||||||Shine on you Crazy Diamond (part 1)||Remember when you were young, you shone like the sun.
<br>Shine on you crazy diamond.
<br>Now there is a look in your eyes, like black holes in the sky.
<br>Shine on you crazy diamond.
<br>You were caught on the cross fire of childhood and stardom,
<br>blown on the steel breeze.
<br>Come on you target for faraway laughter, come on you stranger,
<br>you legend, you martyr, and shine!
<br>
<br>You reached for the secret too soon, you cried for the moon.
<br>Shine on you crazy diamond.
<br>Threatened by shadows at night, and exposed in the light.
<br>Shine on you crazy diamond.
<br>Well you wore out your welcome with random precision,
<br>rode on the steel breeze.
<br>Come on you raver, you seer of visions, come on you painter,
<br>you piper, you prisoner, and shine!
2||1142866721||||||Welcome to the Machine||Welcome, my son, welcome to the machine.
<br>Where have you been? It is all right, we know where you\\'ve been.
<br>You\\'ve been in the pipeline, filling in time,
<br>provided with toys and \\'Scouting for Boys\\'.
<br>You bought a guitar to punish your ma,
<br>and you didn\\'t like school, and you know you\\'re nobody\\'s fool,
<br>so welcome to the machine.
<br>
<br>Welcome, my son, welcome to the machine.
<br>What did you dream? It\\'s all right, we told you what to dream.
<br>You dreamed of a big star, he played a mean guitar,
<br>he always ate in the Steak Bar, he loved to drive in his Jaguar.
<br>So welcome to the machine.
3||1142872180||||||Provaaaaaaa||prova prova prova prova prova prova prova
user=qua c'è lo username (ho evitato di scriverlo)
pass=qua c'è la password come sopra
template=./template.htm
toffset=0
tformat=m/d/y h:i A



news.php

<?php
$digiNewsPath = './news.dat';
require './news.inc.php';


class digiNews
{
var $entries;
function digiNews($disp)
{
global $news, $digiNews;
$tp = fopen($digiNews['template'], 'r');
$loop_code = fread($tp, 4096);
fclose($tp);
$count = 0;
foreach ($news as $entry) {
$data = explode('||', $entry);
$data[1] = date($digiNews['tformat'], $data[1] + $digiNews['toffset'] * 3600);
$this->entries .= $loop_code;
$this->entries = str_replace('{timestamp}', $data[1], $this->entries);
$this->entries = str_replace('{author}', $data[2], $this->entries);
$this->entries = str_replace('{authoremail}', $data[3], $this->entries);
$this->entries = str_replace('{subject}', $data[4], $this->entries);
$this->entries = str_replace('{body}', $data[5], $this->entries);
$count++;
if ($disp != 'all') {
if ($count == $disp) {
break;
}
}
}
}
}
?>

news.inc.php


<?php
$news = array();
$digiNews = array();
$digiNewsTime = time();
$lines = file($digiNewsPath) or die();
foreach ($lines as $line) {
$line = chop($line);
if (($line != '') or (!ereg('^#', $line))) {
if (ereg('^[0-9]', $line)) {
$news[] = $line;
} else {
list ($key, $val) = split('=', $line);
$digiNews[$key] = $val;
}
}
}
$news = @array_reverse($news);
function writenews()
{
global $digiNewsPath, $news, $digiNews;
$data = fopen($digiNewsPath, 'w') or die();
flock($data, 2) or die();
$news = array_reverse($news);
fputs($data, @join("\n", $news)."\n");
while (list ($key, $val) = each ($digiNews)) {
if (($key != '') && ($val != '')) {
fputs($data, $key.'='.$val."\n");
}
}
fclose($data);
}
?>

template.htm (stampa a video delle news)


vabbeh questo è inutile che ve lo scrivo




Vedete qualcosa che non va? :(
 

Discussioni simili