Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: sNews 1.4 code amendments and snippets  (Read 18015 times)

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
sNews 1.4 code amendments and snippets
« on: January 21, 2006, 08:02:52 PM »

I've started a new thread here so that we can keep all the code amendments and snippets offered here in the forum, in one place..hopefully this will make it easier for everyone to track changes as and when they occur.

Please put all your new tested code here..many thanks ;D

Here'e the latest code offered by Luka for sNews v1.4 as of Friday 20th January GMT

http://www.solucija.com/snews/testing/snews.txt

And Alberts version with line numbers

http://snews.awddesign.co.uk/snews/snews14code/snews.php

The latest sql text seems to be as follows

Code: [Select]
CREATE TABLE articles (
  id INT PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(100) DEFAULT NULL,
  seftitle VARCHAR(100) DEFAULT NULL,
  text LONGTEXT,
  textlimit INT(5) NOT NULL DEFAULT '0',
  date DATETIME DEFAULT NULL,
  category INT(8) NOT NULL DEFAULT '0',
  position CHAR(3),
  displaytitle CHAR(3) NOT NULL DEFAULT 'YES',
  displayinfo CHAR(3) NOT NULL DEFAULT 'YES',
  commentable VARCHAR(5) NOT NULL,
  image varchar(30) DEFAULT NULL,
  published INT(3) NOT NULL DEFAULT '1'

);


CREATE TABLE categories (
  id int(8) PRIMARY KEY AUTO_INCREMENT,
  name varchar(40) NOT NULL,
  seftitle VARCHAR(100) DEFAULT NULL,
  description varchar(100) NOT NULL,
  published varchar(4) NOT NULL DEFAULT 'YES'
);

CREATE TABLE comments (
  id INT(11) PRIMARY KEY AUTO_INCREMENT,
  articleid INT(11) DEFAULT '0',
  name varchar(50) DEFAULT '',
  comment TEXT,
  time DATETIME DEFAULT NULL
);

Please report on any problems with the code snippets in this thread ;D

Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
sNews 1.4 code amendments and snippets
« Reply #1 on: January 22, 2006, 03:39:47 PM »

added by analyzerx on 21 Jan 2006

.htaccess

I've noticed some problems with URL rewrites so I've changed it a bit for anyone who has the same problems with me...

.htaccess did not check if the file I asked in the URL actually existed so I could not put anything else in the same folder as snews... (I could not access even my images folder for example...)

so this is my new .htaccess

Code: [Select]
#sNews v1.4
#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5


php_value session.use_trans_sid 0

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)/$ index.php?category=$1 [L,QSA]
RewriteRule ^([a-z_]+)/([^/]+)/ index.php?category=$1&title=$2 [L,QSA]
RewriteRule ^([a-z_]+)/([^/]+)/([^/]+)/ index.php?category=$1&title=$2&commentspage=$3 [L,QSA]

I've added compression but you'll need to uncomment the 2nd and 3rd line...
From there before using rewrites apache will check if the directory/file actually exists...

for example if you have a 1.4 installation try accessing your image folder...
most likely you'll get a snews error...
after changing the .htaccess you will be able to access it... ^_^

Contact form bugfix

also this is a quick fix for the contact form in snews.php 1.4 testing2/3...
find:

Code: [Select]
// CONTACT
function contact() {
if ($_POST['contactform'] == "") {?>



:





:





:





:

 


     


  if (isset($_POST['contactform'])) {
$to = s('website_email');
$subject = s('contact_subject');
$body = l('name') .": ". $_POST['name'] ."n";
$body .= l('email') .": ". $_POST['email'] ."n";
$body .= l('url') .": ". $_POST['weblink'] ."nn";
$body .= l('message') .": ". $_POST['message'] ."n";
if (strlen(clean($_POST['name'])) > 1 AND strlen(clean($_POST['message'])) > 1) {
mail($to, $subject, $body);
echo "

". l('contact_sent') ."

";
  echo "

". l('backhome') ."

";
} else {
echo "

". l('contact_not_sent') ."

";
echo "

". l('message_error') ."

";
echo "

". l('backhome') ."

";
}}}

and replace it with:

Code: [Select]
// CONTACT
function contact() {
if ($_POST['contactform'] == "") {?>



:




:




:




:


 


     




  if (isset($_POST['contactform'])) {
$to = s('website_email');
$subject = s('contact_subject');
$body = l('name') .": ". $_POST['name'] ."n";
$body .= l('email') .": ". $_POST['email'] ."n";
$body .= l('url') .": ". $_POST['weblink'] ."nn";
$body .= l('message') .": ". $_POST['message'] ."n";
if (strlen(clean($_POST['name'])) > 1 AND strlen(clean($_POST['message'])) > 1) {
if ($contact_mail_just_sent != 1) {
mail($to, $subject, $body);
$contact_mail_just_sent = 1;
echo "

". l('contact_sent') ."

";
  echo "

". l('backhome') ."

";
};
} else {
echo "

". l('contact_not_sent') ."

";
echo "

". l('message_error') ."

";
echo "

". l('backhome') ."

";
}}}

^_^ :)
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

George Antoniadis

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 479
sNews 1.4 code amendments and snippets
« Reply #2 on: January 24, 2006, 06:24:00 PM »

This is a basic RSS Feed script until 1.4 is release to the world! ^_^
just place it in the same directory with snews.php
Code: [Select]
header('Content-type: text/xml');
include 'snews.php';

echo '


'.s('website_title').'
'.s('website_title').'
'.s('website').'
Copyright '.s('website_title').'';

$db = mysql_connect(s(dbhost),s(dbuname),s(dbpass));
mysql_select_db(s(dbname)) or die(s(dberror));
$query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 ORDER BY date DESC LIMIT ".s('rss_limit');
$result = mysql_query($query);

while ($r = mysql_fetch_assoc($result)){
$in_cat_name = '';
$in_cat_seftitle = '';

if ($r['category'] != 0) {
$cat_id_temp = $r['category'];
$cat_query = "SELECT * FROM " .s('prefix'). "categories WHERE id = $cat_id_temp";
$cat_result = mysql_query($cat_query);
while ($c = mysql_fetch_array($cat_result)) {
$in_cat_seftitle = $c['seftitle'];
$in_cat_name = $c['name'];
}
} else
{
$in_cat_seftitle = s('home');
$in_cat_name = s('home');
};

$pattern="'<[/!]*?[^<>]*?>'si";
$replace="";
$description = preg_replace($pattern, $replace, stripslashes($r['text']));

echo "";
echo  "". $r['title'] . " (posted in ". $in_cat_name .")";
echo  "". nl2br(stripslashes($r['text'])) ."";
echo  "". s(website) ."".$in_cat_seftitle."/". $r['seftitle'] ."/";
echo  "
";
};


echo '

';

?>

PLEASE BE SURE NOT TO LEAVE ANY BLANK SPACES, LINES OR ANYTHING BEFORE THE FIRST
Logged
How I feel like I'm starless, I'm ready to fade now.
And how I feel like I'm starless, I'm hopeless and greyed out.

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
sNews 1.4 code amendments and snippets
« Reply #3 on: January 24, 2006, 06:46:59 PM »

How to remove the category shown in New Articles:

Posted by Luka - 24th Jan 2006

Code: [Select]
// NEW ARTICLES
function new_articles($number) {
$db = mysql_connect(s('dbhost'),s('dbuname'),s('dbpass'));
mysql_select_db(s('dbname')) or die(s('dberror'));
$query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 1 ORDER BY id DESC LIMIT 0, $number";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$date = date(s('date_format'), strtotime($r['date']));
echo "

$r[title] ";
echo $date;
echo "

"; }
}
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

Jochum Meester

  • Sr. Member
  • ****
  • Karma: 1
  • Posts: 309
    • JochumMeester.com
sNews 1.4 code amendments and snippets
« Reply #4 on: January 26, 2006, 11:29:26 PM »

Could you please also add a default index.php file with all the required functions (like etc., because it's doing nothing for me now... I've copied the 1.3 index.php to this new snewsversion, but it doesn't seem to know the past entries function, and whenever I click a post's title it messes up with CSS, because the path to the CSS is changed because it uses those friendly urls.
Logged

George Antoniadis

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 479
sNews 1.4 code amendments and snippets
« Reply #5 on: January 27, 2006, 12:44:32 AM »

Quote from: JM
Could you please also add a default index.php file with all the required functions (like etc., because it's doing nothing for me now... I've copied the 1.3 index.php to this new snewsversion, but it doesn't seem to know the past entries function, and whenever I click a post's title it messes up with CSS, because the path to the CSS is changed because it uses those friendly urls.

index has not changed... just remember you NEED to use cause without it nothing else will happen
Logged
How I feel like I'm starless, I'm ready to fade now.
And how I feel like I'm starless, I'm hopeless and greyed out.

Jochum Meester

  • Sr. Member
  • ****
  • Karma: 1
  • Posts: 309
    • JochumMeester.com
sNews 1.4 code amendments and snippets
« Reply #6 on: January 27, 2006, 09:04:30 AM »

http://www.iseeyou-designs.com/projects/snewstest/
Stops at past_entries

Perhaps we need another similir topic for problems, to avoid getting all the questions in this one?
Logged

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1716
    • http://www.snewscms.com
sNews 1.4 code amendments and snippets
« Reply #7 on: January 27, 2006, 12:32:38 PM »

Quote from: JM
http://www.iseeyou-designs.com/projects/snewstest/
Stops at past_entries

Perhaps we need another similir topic for problems, to avoid getting all the questions in this one?

Change that to past_articles(3,3);

New Articles and Past Articles. I changed that so we don't confuse entries and articles since Articles is used throught the site and administration.
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
sNews 1.4 code amendments and snippets
« Reply #8 on: January 27, 2006, 12:35:30 PM »

EDIT --> Neva' mind ;)
Logged
"It's only dead fish that goes with the flow... "
Updated

albert

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 405
    • http://www.oswt.co.uk/
sNews 1.4 code amendments and snippets
« Reply #9 on: February 07, 2006, 04:36:19 PM »

Hi

does any one know how to make the email save to a text file.

ie i would like to turn off mail..

Code: [Select]
// mail($to, $subject, $body, $headers);
and then have a txt file to pick up what was posted??
any help would be apeciated.

Albert
Logged
Albert
http://snews.awddesign.co.uk/snews/ site: v1.3
http://snews.awddesign.co.uk/           site: v1.2 http://www.awddesign.co.uk/
“Putting together the largest collection of sNews 1.5 designs. Coming very soon :)

Rehuel Lobato de Mesquita

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 61
sNews 1.4 code amendments and snippets
« Reply #10 on: February 07, 2006, 04:46:08 PM »

Code: [Select]
$mailbody = "To: ".$to."rn";
$mailbody .= "Subject: ".$subject."rn";
$mailbody .= "Header: ".$headers."rn";
$mailbody .= "Message: ".$message;
$filename = "Mail-from-".$to.".txt";
$fp = fopen($filename, "w");
if (!$fp) die ("cannot open the file");
fputs($fp, $mailbody, 4096);
fclose($fp);
?>

This should do it, I guess
Logged
Stretsh Out...

Procrastination is like masturbation. You do it till you figure out you're only screwing yourself!

Mario

  • Newbie
  • *
  • Karma: 0
  • Posts: 43
sNews 1.4 code amendments and snippets
« Reply #11 on: February 07, 2006, 05:01:55 PM »

Quote from: Stretsh
Code: [Select]
$mailbody = "To: ".$to."rn";
$mailbody .= "Subject: ".$subject."rn";
$mailbody .= "Header: ".$headers."rn";
$mailbody .= "Message: ".$message;
$filename = "Mail-from-".$to.".txt";
$fp = fopen($filename, "w");
if (!$fp) die ("cannot open the file");
fputs($fp, $mailbody, 4096);
fclose($fp);
?>

This should do it, I guess

Nice!

Just a thought. Instead of writing it to a plain txt file writing it to a xml/rss file would be nice (with the right syntax of course).  This way we could check incoming messages automaticly with a rss feed reader. Opera has a feed reader built in - not sure about other browsers.
Logged

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1716
    • http://www.snewscms.com
sNews 1.4 code amendments and snippets
« Reply #12 on: February 07, 2006, 05:05:07 PM »

Quote from: Mario

This way we could check incoming messages automaticly with a rss feed reader.


Yeah, and so could anyone else. It would be wise to store the xml file to some wierd folder and name it 2349608.xml  ;D
Logged

Mario

  • Newbie
  • *
  • Karma: 0
  • Posts: 43
sNews 1.4 code amendments and snippets
« Reply #13 on: February 07, 2006, 05:12:38 PM »

I Agree!

Something like this would take care of that:

Code: [Select]
$s['myprivatefeed'] = "myprivatefeed.xml; // make sure to change this to a hard to guess url; eg 123Q1aa.xml
Logged

albert

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 405
    • http://www.oswt.co.uk/
sNews 1.4 code amendments and snippets
« Reply #14 on: February 08, 2006, 03:55:35 AM »

Hi

thank you for the replay's to the email save to text file.

i did change this
Code: [Select]
$fp = fopen($filename, "w");to this
Code: [Select]
$fp = fopen($filename, "a");
and works great. Big thank you :)

Now with the problem with people reading my file, what a bumer. So the best way would be to incert this into
the data base.


Code: [Select]
mail("spam@gmail.com","Web Site email from:web site","From: ".$Name."<".$Emailaddress.">");

$link = mysql_connect("localhost","root","passmyspam");

mysql_select_db("snews",$link);
$query="insert into mail (Name,Email,Weblink,Message) values ('".$Name."','".$Email."','".$Weblink."','".$Message."')";
mysql_query($query);

i think this may work, What do ya think ?

Albert
Logged
Albert
http://snews.awddesign.co.uk/snews/ site: v1.3
http://snews.awddesign.co.uk/           site: v1.2 http://www.awddesign.co.uk/
“Putting together the largest collection of sNews 1.5 designs. Coming very soon :)
Pages: [1] 2