<?php
/*****************************************************************
* Spacemarc News
* Version: 1.2.0
* Author and copyright (C): Marcello Vitagliano
* Web site: http://www.spacemarc.it
* License: GNU General Public License
*
* 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 3
* of the License, or (at your option) any later version.
*
* Current file: view.php
*****************************************************************/
header('Content-type: text/html; charset=ISO-8859-1');
//includo il file di configurazione
require_once (dirname(__FILE__) . '/config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
//apro la connessione a mysql
$db = @mysql_connect($db_host, $db_user, $db_password);
@mysql_select_db($db_name, $db);
//seleziono l'ID minore e maggiore delle news
$result = mysql_query("SELECT MIN(id) AS MinID, MAX(id) AS MaxID FROM $tab_news");
$row = @mysql_fetch_array($result);
//se c'è l'id della notizia inviato via GET ed è di tipo numerico ed è presente in tabella visualizzo la notizia
if (isset($_GET['id']) && preg_match('/^[0-9]{1,8}$/', $_GET['id']) && $_GET['id'] <= $row['MaxID'] && $_GET['id'] >= $row['MinID']) {
//aumento il numero di letture della notizia
mysql_query("UPDATE $tab_news SET letture=letture+1 WHERE id=" . intval($_GET['id']));
//seleziono la notizia richiesta dall'utente
$result3 = mysql_query("SELECT nt.id, nt.titolo, nt.testo, nu.nome_cognome, nt.data_pubb, nt.letture, nt.stampe, nt.immagine, nt.nosmile, nu.mostra_link, nu.email, nu.sito, nu.user_id FROM $tab_news nt JOIN $tab_utenti nu ON nu.user_id=nt.user_id WHERE nt.id=" . intval($_GET['id']));
$row3 = mysql_fetch_array($result3);
$testo = nl2br($row3['testo']);
$img_view = ($row3['immagine'] != "") ? "<div class=\"imgap\"><img src=\"" . $row3['immagine'] . "\" border=\"1\" alt=\"immagine\" width=\"96\" height=\"86\" /></div>" : NULL;
switch ($row3['mostra_link']) {
case "nome":
$profilo_autore = $row3['nome_cognome'];
break;
case "email":
$newemail = explode("@", $row3['email']);
$profilo_autore = "
<script language=\"javascript\" type=\"text/javascript\">function nospam(user,domain){ document.location.href = \"mailto:\" + user + \"@\" + domain; }</script>
<a href=\"javascript:nospam('$newemail[0]','$newemail[1]')\" class=\"piccolo\" title=\"Indirizzo email\">" . $row3['nome_cognome'] . "</a>";
break;
case "sito":
$profilo_autore = ($row3['sito'] == '') ? $row3['nome_cognome'] : "<a href=\"" . $row3['sito'] . "\" target=\"_blank\" class=\"piccolo\" title=\"Sito web dell'autore [Nuova finestra]\">" . $row3['nome_cognome'] . "</a>";
break;
case "profilo":
$profilo_autore = "<a href=\"javascript:;\" onclick=\"window.open('autore.php?user_id=" . $row3['user_id'] . "', '', 'width=420, height=300, resizable=1, scrollbars=1, location=1, status=1');\" title=\"Visualizza il profilo dell'autore [Popup]\" class=\"piccolo\">" . $row3['nome_cognome'] . "</a>";
break;
default:
$profilo_autore = $row3['nome_cognome'];
}
//estraggo le impostazioni
$conf = mysql_query("SELECT nome_sito, url_sito, sfondo_titolo, sfondo_notizia, sfondo_strumenti, larghezza, larghezza_pager, formato_data FROM $tab_config");
$rowconf = mysql_fetch_array($conf);
function bbCode($testo) {
global $img_path, $row3;
//sostituisco i bbcode con i tags HTML e con gli smlies
if ($row3['nosmile'] == 0) {
$replace = array(
'[b]' => '<b>',
'[/b]' => '</b>',
'[i]' => '<i>',
'[/i]' => '</i>',
'[u]' => '<u>',
'[/u]' => '</u>',
'[ul]' => '<ul>',
'[/ul]' => '</ul>',
'[li]' => '<li>',
'[/li]' => '</li>',
'&' => '&',
':cool:' => '<img src="' . $img_path . '/cool.gif" alt="cool" />',
':)' => '<img src="' . $img_path . '/smile.gif" alt="smile" />',
'):' => '<img src="' . $img_path . '/mad.gif" alt="mad" />',
':p' => '<img src="' . $img_path . '/tongue.gif" alt="tongue" />',
':D' => '<img src="' . $img_path . '/biggrin.gif" alt="biggrin" />',
';)' => '<img src="' . $img_path . '/wink.gif" alt="wink" />',
':o' => '<img src="' . $img_path . '/ohh.gif" alt="ohh" />',
':zizi:' => '<img src="' . $img_path . '/zizi.gif" alt="zizi" />',
':(' => '<img src="' . $img_path . '/sad.gif" alt="sad" />',
':green:' => '<img src="' . $img_path . '/mrgren.gif" alt="mrgren" />',
':dotto:' => '<img src="' . $img_path . '/dotto.gif" alt="dotto" />',
':cry:' => '<img src="' . $img_path . '/cry.gif" alt="cry" />',
':parolaccia:' => '<img src="' . $img_path . '/parolaccia.gif" alt="parolaccia" />',
':incupito:' => '<img src="' . $img_path . '/incupito.gif" alt="incupito" />',
':stordito:' => '<img src="' . $img_path . '/stordito.gif" alt="stordito" />',
':info:' => '<img src="' . $img_path . '/info.png" alt="info" />',
':star:' => '<img src="' . $img_path . '/star.png" alt="star" />',
':alert:' => '<img src="' . $img_path . '/alert.png" alt="alert" />',
':???:' => '<img src="' . $img_path . '/question.png" alt="question" />',
':check:' => '<img src="' . $img_path . '/check.png" alt="check" />',
':wiki:' => '<img src="' . $img_path . '/wikipedia.png" alt="wikipedia" />',
':chat:' => '<img src="' . $img_path . '/chat.png" alt="chat" />',
':www:' => '<img src="' . $img_path . '/www.png" alt="www" />',
':man:' => '<img src="' . $img_path . '/man.png" alt="man" />',
':mail:' => '<img src="' . $img_path . '/mail.png" alt="mail" />',
':fb:' => '<img src="' . $img_path . '/facebook.gif" alt="facebook" />',
':li:' => '<img src="' . $img_path . '/linkedin.gif" alt="linkedin" />',
':ms:' => '<img src="' . $img_path . '/myspace.gif" alt="myspace" />',
':tw:' => '<img src="' . $img_path . '/twitter.gif" alt="twitter" />',
':gw:' => '<img src="' . $img_path . '/gwave.png" alt="gwave" />'
);
$testo = strtr($testo, $replace);
}
else {
$replace = array(
'[b]' => '<b>',
'[/b]' => '</b>',
'[i]' => '<i>',
'[/i]' => '</i>',
'[u]' => '<u>',
'[/u]' => '</u>',
'[ul]' => '<ul>',
'[/ul]' => '</ul>',
'[li]' => '<li>',
'[/li]' => '</li>'
);
$testo = strtr($testo, $replace);
}
//cerco eventuali bbcode URL, email, dimensione testo, colore testo, quote ecc...
$testo_cerca = array(
"{\[email\](\r\n|\r|\n)*([a-zA-Z0-9\._-]+@(([a-zA-Z0-9_-])+\.)+[a-z]{2,6})\[/email\]}siU",
"{\[email=(\w[\w\-\.\+]*?@\w[\w\-\.]*?\w\.[a-zA-Z]{2,4})\](.+)?\[\/email\]}siU",
"{(\[)(url)(])((http|ftp|https)://)([^;<>\*\(\)\"\s]*)(\[/url\])}siU",
"{(\[)(url)(=)(['\"]?)((http|ftp|https)://)([^;<>\*\(\)\"\s]*)(\\4])(.*)(\[/url\])}siU",
"{(\[)(callto)(])((callto):)([^;<>\*\(\)\"\s]*)(\[/callto\])}siU",
"{(\[)(callto)(=)(['\"]?)((callto):)([^;<>\*\(\)\"\s]*)(\\4])(.*)(\[/callto\])}siU",
"{(\[)(size)(=)(['\"]?)([0-9]*)(\\4])(.*)(\[/size\])}siU",
"{\[img\](\r\n|\r|\n)*((http|https)://([^;<>\*\(\)\"\s]+)|[a-z0-9/\\\._\- ]+)\[/img\]}siU",
"{\[quote\](\r\n|\r|\n)*(.+)\[/quote\]}siU",
"{\[code\](\r\n|\r|\n)*(.+)\[/code\]}siU",
"{\[yt\]([0-9A-Za-z-_]{11})\[/yt]}siU"
);
//...e li sostituisco con gli appositi tags HTML
$testo_sostituisci = array(
"<a href=\"mailto:\\2\">\\2</a>",
"<a href=\"mailto:\\1\">\\2</a>",
"<a href=\"\\4\\6\" target=\"_blank\">\\4\\6</a>",
"<a href=\"\\5\\7\" target=\"_blank\">\\9</a>",
"<a href=\"\\4\\6\" target=\"_blank\">\\4\\6</a>",
"<a href=\"\\5\\7\" target=\"_blank\">\\9</a>",
"<span style=\"font-size: \\5pt;\">\\7</span>",
"<img src=\"\\2\" border=\"0\" alt=\"immagine\" title=\"\" />",
"<div style=\"background-color:#FFFFFF; margin:0 auto; width:90%;\" class=\"text2\"><b>Citazione</b></div><div style=\"background-color:#F9F9F9; margin:0 auto; width:90%; height: auto; border: 1px solid #DEE3E7; padding: 3px;\" class=\"text2\">\\2</div>",
"<div style=\"background-color:#FFFFFF; margin:0 auto; width:100%;\" class=\"text2\"><b>Codice</b></div><div style=\"background-color:#F9F9F9; width: 560px; height: auto; padding:3px; line-height: 7px; border: 1px solid #E1E1E1; white-space: nowrap; overflow: auto;\" class=\"text\"><pre>\\2</pre></div>",
"<object width=\"320\" height=\"265\"><param name=\"movie\" value=\"http://www.youtube.com/v/\\1&hl=it&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/\\1&hl=it&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"320\" height=\"265\"></embed></object>"
);
$testo = preg_replace($testo_cerca, $testo_sostituisci, $testo);
return $testo;
}
?>
<title>
<?php echo $rowconf['nome_sito']; ?> -
<?php echo $row3['titolo']; ?>
</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="Feed RSS News" href="<?php echo $rowconf['url_sito'] . "/" . $news_dir . "/rss.php"; ?>" />
</head>
<body>
<?php
switch ($rowconf['formato_data']) {
case 1:
$formato_data = strftime("%a %d %b %Y %H:%M", $row3['data_pubb']);
break;
case 2:
$formato_data = str_replace("ì", "ì", strftime("%A %d %B %Y %H:%M", $row3['data_pubb']));
break;
case 3:
$formato_data = strftime("%d/%m/%Y %H:%M", $row3['data_pubb']);
break;
case 4:
$formato_data = strftime("%d %b %Y %H:%M", $row3['data_pubb']);
break;
case 5:
$formato_data = strftime("%d %B %Y %H:%M", $row3['data_pubb']);
break;
}
echo "<div id=\"container\" style=\"width: " . $rowconf['larghezza'] . "px\">\n";
echo "<div id=\"titolo_art\" class=\"text\" style=\"background-color: " . $rowconf['sfondo_titolo'] . "\"><b>" . $row3['titolo'] . "</b> <span class=\"text2\"> di $profilo_autore - $formato_data</span></div>\n";
echo "<div id=\"body_art\" class=\"text\" style=\"background-color: " . $rowconf['sfondo_notizia'] . "\">$img_view " . bbCode($testo) . "<br /><br /><br /><br /></div>\n";
//condivisione news nei social networks
echo "<br /><div id=\"sbookmark\" class=\"text2\">Condividi: <a href=\"http://www.facebook.com/sharer.php?u=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&t=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/facebook.gif\" border=\"0\" alt=\"facebook\" title=\"Facebook\" /></a> <a href=\"http://twitter.com/home?status=" . $row3['titolo'] . " - " . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "\" target=\"_blank\"><img src=\"$img_path/twitter.gif\" border=\"0\" alt=\"twitter\" title=\"Twitter\" /></a> <a href=\"http://www.linkedin.com/shareArticle?mini=true&url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&title=" . $row3['titolo'] . "&summary=&source=Add to Any\" target=\"_blank\"><img src=\"$img_path/linkedin.gif\" border=\"0\" alt=\"linkedin\" title=\"LinkedIn\" /></a> <a href=\"http://www.myspace.com/Modules/PostTo/Pages/?u=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&t=" . $row3['titolo'] . "&l=2\" target=\"_blank\"><img src=\"$img_path/myspace.gif\" border=\"0\" alt=\"myspace\" title=\"MySpace\" /></a> <a href=\"http://technorati.com/faves?add=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "\" target=\"_blank\"><img src=\"$img_path/technorati.gif\" border=\"0\" alt=\"technorati\" title=\"Technorati\" /></a> <a href=\"http://it.myweb2.search.yahoo.com/myresults/bookmarklet?u=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&t=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/yahoo.gif\" border=\"0\" alt=\"yahoo\" title=\"Yahoo!\" /></a> <a href=\"http://www.google.com/bookmarks/mark?op=add&bkmk=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&title=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/google.gif\" border=\"0\" alt=\"google\" title=\"Google bookmarks\" /></a> <a href=\"http://reddit.com/submit?url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&title=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/reddit.gif\" border=\"0\" alt=\"reddit\" title=\"Reddit\" /></a> <a href=\"http://www.wikio.it/vote?url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "\" target=\"_blank\"><img src=\"$img_path/wikio.gif\" border=\"0\" alt=\"wikio\" title=\"Wikio\" /></a> <a href=\"http://oknotizie.alice.it/post.html.php?url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&title=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/okno.gif\" border=\"0\" alt=\"okno\" title=\"OkNotizie\" /></a> <a href=\"http://del.icio.us/post?url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "\" target=\"_blank\"><img src=\"$img_path/delicious.gif\" border=\"0\" alt=\"del.icio.us\" title=\"Del.icio.us\" /></a> <a href=\"http://digg.com/submit?phase=2&url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&title=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/digg.gif\" border=\"0\" alt=\"Digg\" title=\"Digg\" /></a> <a href=\"http://segnalo.com/post.html.php?url=" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row3['id'] . "&title=" . $row3['titolo'] . "\" target=\"_blank\"><img src=\"$img_path/segnalo.gif\" border=\"0\" alt=\"Segnalo\" title=\"Segnalo\" /></a></div>\n";
echo "<div id=\"tool_art\" class=\"text2\" style=\"background-color: " . $rowconf['sfondo_strumenti'] . "\"><a href=\"archivio.php\" title=\"Tutte le news pubblicate\" class=\"piccolo\"><img src=\"$img_path/folder.png\" border=\"0\" alt=\"Archivio\" />Archivio</a> <a href=\"search.php\" title=\"Cerca un termine nelle news\" class=\"piccolo\"><img src=\"$img_path/search.png\" border=\"0\" alt=\"Cerca\" />Cerca</a> <a href=\"javascript:;\" onclick=\"window.open('segnala.php?id=" . $row3['id'] . "', '', 'width=400, height=300, resizable=1, scrollbars=1, location=1, status=1');\" title=\"Segnala questa notizia [Popup]\" class=\"piccolo\"><img src=\"$img_path/mail.png\" border=\"0\" alt=\"Invia\" />Invia</a> <a href=\"print.php?id=" . $row3['id'] . "\" target=\"_blank\" title=\"Versione stampabile [Nuova finestra]\" class=\"piccolo\"><img src=\"$img_path/print.png\" border=\"0\" alt=\"Stampa\" />Stampa</a> <a href=\"getpdf.php?id=" . $row3['id'] . "\" title=\"Esporta in PDF\" class=\"piccolo\" target=\"_blank\"><img src=\"$img_path/pdf.gif\" border=\"0\" alt=\"PDF\" />PDF</a> <a href=\"rss.php\" title=\"Feed RSS\" class=\"piccolo\"><img src=\"$img_path/rss.gif\" border=\"0\" alt=\"RSS\" />RSS</a> Letture " . $row3['letture'] . ", stampe " . $row3['stampe'] . " <a href=\"http://www.spacemarc.it\" target=\"_blank\" class=\"piccolo\" title=\"Copyright script\">©</a></div>\n";
// mostro la prima notizia precedente quella corrente
$result4 = mysql_query("SELECT id, titolo FROM $tab_news WHERE id < " . $row3['id'] . " ORDER BY id DESC LIMIT 1");
$row4 = mysql_fetch_array($result4);
$idprec = $row4['id'];
$titoloprec = $row4['titolo'];
echo "<div class=\"pager_art\" style=\"width: " . $rowconf['larghezza_pager'] . "px\">";
if ($idprec >= 1) {
echo "<img src=\"$img_path/idnew2.gif\" border=\"0\" alt=\"\" /> <b>Precedente</b><br /><a href=\"view.php?id=$idprec\" title=\"Notizia precedente\" class=\"piccolo\">$titoloprec</a></div>";
}
else {
echo " </div>";
}
//mostro la prima notizia successiva a quella corrente
$result5 = mysql_query("SELECT id, titolo FROM $tab_news WHERE id > " . $row3['id'] . " ORDER BY id ASC LIMIT 1");
$row5 = mysql_fetch_array($result5);
if ($_GET['id'] > $row5['id']) {
echo "</div>";
}
else {
$idsucc = $row5['id'];
$titolosucc = $row5['titolo'];
echo "<div class=\"pager_art\" align=\"right\" style=\"width: " . $rowconf['larghezza_pager'] . "px\"><b>Successiva</b> <img src=\"$img_path/idnew.gif\" border=\"0\" alt=\"\" /><br /><a href=\"view.php?id=$idsucc\" title=\"Notizia successiva\" class=\"piccolo\">$titolosucc</a></div>";
echo "</div>";
}
//chiudo la connessione con mysql
mysql_close($db);
//altrimenti se l'id della notizia passato via GET non è valido mostro la pagina normale col messaggio di errore
}
else {
?>
<title>Notizia inesistente
</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="text2" style="width: 400px;"><b>Notizia inesistente</b><br /><br />Spiacenti, la notizia che hai selezionato non esiste.<br />Vai all'
<a href="archivio.php" title="Archivio delle notizie" class="piccolo">archivio</a> delle notizie o fai una
<a href="search.php" title="Cerca" class="piccolo">ricerca</a>.
</div>
<?php
}
?>
</body>
</html>