Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Modify Existing PHP code for use with sNews  (Read 4829 times)

Datu Puti

  • Newbie
  • *
  • Karma: 0
  • Posts: 43
Modify Existing PHP code for use with sNews
« on: November 25, 2006, 04:25:37 PM »

HI all,

Love this sNews! i came across a php script that will plug in a random quote every time the browser refreshes. What i want is to use the same code to output a country profile on a daily weekly monthly basis. not every time the browser refreshes.

Here is the code:

/* Config Part --------------------------------------------------------------------------------------------------------------*/

$random = true;                           // if you want random, keep true, set to false if want sequential
$directory = " ";                        //  Webserver path to your quote files with / on end!
$quotefile = "randomquote.inc";                                                         //  The Random Quote file
$quotecountfile = "displayquote.inc";                                                   //  The Display Quote file (IF SEQUENTIAL!)

/* End of Config Part -------------------------------------------------------------------------------------------------------*/

$quotes = file($directory.$quotefile);
$number = count($quotes);

if($random){
   $num = rand(0,$number-1);
}
else{
   $num = file($directory.$quotecountfile);
   $num = $num[0]+1;
   if($num>$number-1){ // If ran out of quotes, start again!
      $num=0;   
   }
   if (file_exists($directory.$quotecountfile)) {
      $nu = fopen ($directory.$quotecountfile, "w");
      fputs($nu,$num);
   }
   else {
      die("Cant Find $quotecountfile");
   }
}

// display the quote on the page

echo "$quotes[$num]";
?>

Can it be done? Is it easy to add the requested features?

or does someone know of an existing php script that already does this? reads code including html tags from a single line text file and displays it daily weekly or monthly?

I am doing this website for a non profit entity and of course as we all know non profits are on tight budgets but need exposure to increase donations etc..

Thnx guys..

Love sNews! Viva sNews!
Logged
Regards from the beautiful 7000 Islands of the Philippines! Mabuhay!

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

ozwebfx

  • Newbie
  • *
  • Karma: 2
  • Posts: 18
  • G'day!
    • ozwebfx
Re: Modify Existing PHP code for use with sNews
« Reply #2 on: December 05, 2007, 03:29:20 AM »

G'day!

I'm also trying to use the same script which is from: http://www.cj-design.com/products/free_downloads/php_scripts/cjrandomquote

I haven't made any modifications but it doesn't work on my site, the page takes ages to load & it destroys some page formatting .. is anyone using this successfully or does anyone have another random quote script which can be used with sNews 1.6.0 ME?

ozwebfx

  • Newbie
  • *
  • Karma: 2
  • Posts: 18
  • G'day!
    • ozwebfx
Re: Modify Existing PHP code for use with sNews
« Reply #3 on: December 05, 2007, 06:01:36 AM »

I found this one: http://www.mindpalette.com/tutorials/random/index.php

It worked nicely.

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Modify Existing PHP code for use with sNews
« Reply #4 on: December 05, 2007, 10:17:43 AM »

I'm using a super-simple random quote script, found somewhere on the old snews forum (solucija.com). You can see it in action at www.frdk.com/snews/

1. random.php
Quote
<?php
   $quotes[] = '<p>“There’s no problem so big that it can’t be run away from.”</p>
   <p><cite>(Snoopy the dog)</cite></p>';
   $quotes[] = '<p>“Take a cookie. I promise—by the time you’re done eating it, you’ll feel right as rain.”</p>
   <p><cite>(The Oracle)</cite></p>';
   $quotes[] = '<p>“It will grow up to be a quote.”</p>
   <p><cite>(Unknown Genius)</cite></p>';
   $quotes[] = '<p>“Everything in this book may be wrong.”</p>
   <p><cite>(Richard Bach)</cite></p>';

    srand ((double) microtime() * 1000000);
    $randomquote = rand(0,count($quotes)-1);
 ?>
Save in a file and name it, for example, random.php
Obvious note: change the actual contents, within the single quote marks for each $quotes[] instance.

2. snews.php (you can put this anywhere, I have mine a after breadcrumbs() function.)
Quote
// RANDOM QUOTE
function quotes() {
    include('includes/random.php');
    echo $quotes[$randomquote];
}

3. index.php
Insert <php quotes(); ?> wherever you want the random text to appear. You can of course use philmoz' Function use mod to put the random thing anywhere.
You can of course use any content within random.php, doesn't have to be text. I've used it for rand om ad blocks, and have thought about using it for random video clips. Anything's possible™. ;)
Enjoy.
« Last Edit: December 05, 2007, 10:21:07 AM by Fred K (agentsmith) »
Logged