TinyPortal

Development => Block Codes => Topic started by: crip on February 06, 2006, 04:35:58 PM

Title: Random Quotes
Post by: crip on February 06, 2006, 04:35:58 PM
Little php script that show a Random Quote in a phpbox / block.

Title: Re: Random Quotes
Post by: rapture on February 08, 2006, 03:16:12 AM
Funny stuff.  I might install.  Looks as easy as uploading 3 files and calling some PHP in a side block.

Thanks for sharing.
Title: Re: Random Quotes
Post by: Ray on February 08, 2006, 04:37:12 AM
I can never get that command to work  include "./quote/randomquote.php";

ok my quote folder is rranderson\arcade\quote or http://www.rranderson.com/arcade/quote

would that path work because I keep getting a
$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]"; ?>error

in randomquote.pnp i have $directory = "./quote/";
in the PHP block I have  include "./quote/randomquote.php";
What am I doing wrong - time for me to learn this

Thanks
Title: Re: Random Quotes
Post by: IchBin on February 08, 2006, 07:40:17 PM
try the path without the "."

include "/quote/randomquote.php";
Title: Re: Random Quotes
Post by: crip on February 08, 2006, 08:20:19 PM
After you upload your "quote" folder in your forum root, just go to a phpbox and add what Incbin put..

this:
****************************
include "/quote/randomquote.php";
****************************
nothing more, nothing less.

It's EZ now guys, once Bloc and crew told me how to add it..Lol..

Later, crip~ ;D
Title: Re: Random Quotes
Post by: Ray on February 08, 2006, 11:54:32 PM
Quote from: IchBinâââ,¬Å¾Ã,¢ on February 08, 2006, 07:40:17 PM
try the path without the "."

include "/quote/randomquote.php";
Get the same error errr I know it can not be this hard
Title: Re: Random Quotes
Post by: IchBin on February 09, 2006, 02:07:10 AM
Did you try this?


include "/rranderson/arcade/quote/randomquote.php";
Title: Re: Random Quotes
Post by: crip on February 09, 2006, 10:32:38 AM
I just checked my phpbox .. this is all thats in it.
include "./quote/randomquote.php";

Ray, be sure you have the path from your randomquote.php correct .. the "quotes" folder Must be in the root of your Forum / Arcade / Where ever, Or the call for Randomquote.php will send errors until your get the path right.. 

I have my "quote" Folder inside of my "Forum" Folder where / Smileys / Themes / Packages / Sources / et-ceteras..are.

Later, Crip~ ;D
Title: Re: Random Quotes
Post by: Rasyr on February 09, 2006, 01:52:32 PM
Try using:

include "quote/randomquote.php";

see if that works.

or perhaps try

require("quote/randomquote.php");

with and without the leading slash before the word "quote".
Title: Re: Random Quotes
Post by: Ray on February 09, 2006, 06:08:23 PM
Quote from: IchBinâââ,¬Å¾Ã,¢ on February 09, 2006, 02:07:10 AM
Did you try this?


include "/rranderson/arcade/quote/randomquote.php";

no work
Title: Re: Random Quotes
Post by: Ray on February 09, 2006, 06:11:17 PM
Quote from: Rasyr on February 09, 2006, 01:52:32 PM
Try using:

include "quote/randomquote.php";

see if that works.

or perhaps try

require("quote/randomquote.php");

with and without the leading slash before the word "quote".

NO no work here also -- will look at ir more later
Title: Re: Random Quotes
Post by: crip on February 09, 2006, 09:14:19 PM
Ray,

in the file randomquote.php make sure you have a path set similar to this:

$random = true;    
$directory = "/home/www/public_html/forum/quote/"; 
$quotefile = "randomquote.inc";
$quotecountfile = "displayquote.inc";


Leave
Title: Re: Random Quotes
Post by: Ray on February 09, 2006, 10:07:12 PM
Quote from: cripâ€Ã,¦ on February 09, 2006, 09:14:19 PM
Ray,

in the file randomquote.php make sure you have a path set similar to this:

$random = true;    
$directory = "/home/www/public_html/forum/quote/"; 
$quotefile = "randomquote.inc";
$quotecountfile = "displayquote.inc";


Leave
  • $quotefile
    and
  • $quotecountfile

    as it looks here, and it should work.

    crip~

Tried this
$random = true;
$directory = "/rranderson/arcade/quote/";    //Put the correct path//
$quotefile = "randomquote.inc";         //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//

No work -- I always get that same error -- all files are located in the quote folder

Title: Re: Random Quotes
Post by: crip on February 09, 2006, 11:12:35 PM
Path from your www / or public_html..
Last try:

Title: Re: Random Quotes
Post by: Ray on February 09, 2006, 11:50:28 PM
Quote from: cripâ€Ã,¦ on February 09, 2006, 11:12:35 PM
Path from your www / or public_html..
Last try:

  • $directory = "/home/rranderson/public_html/arcade/quote/";

    Hope you get it working RayR.

    crip
Im not on a linux computer I use windows with IIs so that may be the problem.. the paths are different. For me it is d:\rranderson\arcade\quote -- umm maybe I will try that path
Title: Re: Random Quotes
Post by: crip on February 09, 2006, 11:56:09 PM
Your right Ray.......
now ya tell me.. ;D
Title: Re: Random Quotes
Post by: Ray on February 10, 2006, 05:38:34 PM
For me it is d:\rranderson\arcade\quote -- umm maybe I will try that path

Still no work -- I have never got the command include to work
Title: Re: Random Quotes
Post by: feline on February 10, 2006, 07:04:08 PM
Quote from: Ray on February 10, 2006, 05:38:34 PM
For me it is d:\rranderson\arcade\quote -- umm maybe I will try that path

Still no work -- I have never got the command include to work

to add one \ at the end Ray ...

Fel
Title: Re: Random Quotes
Post by: Ray on February 15, 2006, 05:26:21 PM
tried that also - here is the error
$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]"; ?>
Title: Re: Random Quotes
Post by: L1 on February 16, 2006, 08:15:31 AM
I played with this a long time and I know nothing about code but was getting the same error that ray has here, basically showing the code from randomquote.php instead of a quote.  I got it to work by doing this:

$directory = "./quote/";    //Put the correct path// 

and this

include "./quote/randomquote.php";

why that works I have no idea  :laugh:

maybe something to do with server setting?

great little mod, I love it  8)

thanks alot
Title: Re: Random Quotes
Post by: L1 on February 16, 2006, 08:22:49 AM
I just remembered I also did this:

I put "php" after <? at the beginning of randomquote.php

so the config part looks like this:

<?php
/* Config Part --------------------------------------------------------------------------------------------------------------*/
$random = true;      
$directory = "./quote/";    //Put the correct path// 
$quotefile = "randomquote.inc";           //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//
/* End of Config Part -------------------------------------------------------------------------------------------------------*/

and now I notice that when I take out the "php" it doesn't work anymore so that might be the only change that needs to be made, so try that first.

good luck

:)
Title: Re: Random Quotes
Post by: crip on February 16, 2006, 10:19:16 AM
Sure,
anything that "(works)" .. suppose it's a bit different on different servers..
Title: Re: Random Quotes
Post by: Ray on February 16, 2006, 04:20:36 PM
Quote from: L1 on February 16, 2006, 08:15:31 AM
I played with this a long time and I know nothing about code but was getting the same error that ray has here, basically showing the code from randomquote.php instead of a quote.  I got it to work by doing this:

$directory = "./quote/";    //Put the correct path// 

and this

include "./quote/randomquote.php";

why that works I have no idea  :laugh:

maybe something to do with server setting?

great little mod, I love it  8)

thanks alot
That fixed it for me and also the adding the php.

Now to figure how to make it center when displayed? -- thanks all for the tips
Title: Re: Random Quotes
Post by: Ray on February 17, 2006, 03:03:59 AM
OK now that it is working -- How to center the qoute text in a block??
Title: Re: Random Quotes
Post by: crip on February 22, 2006, 12:20:04 AM
<p align="center"><? php quotes  ?></p>
or
<center>
<? php quotes
?>
</center>

Title: Re: Random Quotes
Post by: Ray on February 22, 2006, 03:15:53 PM
Quote from: ÂÃ,»cripÂÃ,« on February 22, 2006, 12:20:04 AM
<p align="center"><? php quotes  ?></p>
or
<center>
<? php quotes
?>
</center>



I fixed it and had to do it in the randomquote.php file

and all the trouble I had and it was just becaue the php after the <? was not their
Title: Re: Random Quotes
Post by: crip on February 22, 2006, 03:24:30 PM
Man learns something new everyday .. ya know Rayzer..  ;)
Title: Re: Random Quotes
Post by: Mitch on February 22, 2006, 03:28:20 PM
Soo I tried to install this and will try again.
I think the reason I couldnt get it to work was cause I started on page one with all the helpful editing where as I should have looked back to see where the actual solution was. :)
Title: Re: Random Quotes
Post by: crip on February 22, 2006, 03:34:04 PM
need any help?
Title: Re: Random Quotes
Post by: Mitch on February 22, 2006, 03:42:15 PM
Eh not right now I have to get back to school and stuff.
So if you want to pm me directions that would be cool.
Title: Re: Random Quotes
Post by: crip on February 22, 2006, 03:56:25 PM
Directions in .zip & on first post on this thread.
Title: Re: Random Quotes
Post by: Mitch on February 22, 2006, 08:02:10 PM
Did you just do that or have they been there?
I always feel so dumb around you guys. ^_-
Title: Re: Random Quotes
Post by: crip on February 22, 2006, 08:05:35 PM
I put it there when I 1st posted it. :)
Title: Re: Random Quotes
Post by: Mitch on February 23, 2006, 12:19:00 AM
-_-
Title: Re: Random Quotes
Post by: Mitch on February 23, 2006, 02:09:34 AM
Ok so I uploaded all three files to the copy and pasted name quote in my forums root folder.

Looks like /public_html/forums/quote

So I updated my include statement in the php block to:
include "./forums/quote/randomquote.php";

I also tried it without the .

Any I dea of what I am doing wrong?
----------------------------------------------------------------------
My Current Code (randomquote.php)

<?
/* Config Part --------------------------------------------------------------------------------------------------------------*/
$random = true;    
$directory = "home/www/public_html/quote/";    //Put the correct path// 
$quotefile = "randomquote.inc";         //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//
/* 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]";
?>



----------------------------------------------------------------------
Quote
README:

Upload all 3 files into a directory preferably named 'quote'  into the root of your forum.....
URL: www.yoursite.com/quote/randomquote.php   //You'll figure it out the right path//
-------------------------------------------------------------------------------------------------------------
randomquote.php   //Fix the paths in this file//
-------------------
displayquote.inc  //Counts your quotes, could be optionable//
------------------
randomquote.inc  //Put all quotes in one line in this file//
---------------------------------------------------------------------------------------------------------------

//Put this in a phpbox/block//
//*--------------------------------------//*
include "./quote/randomquote.php";
//*--------------------------------------//*

//At each reload / refresh you get a new Random quote//
//The more quotes you have, the more Random they become//


///////enjoy, crip~/////////
[/qoute]
Title: Re: Random Quotes
Post by: TwinsX2Dad on February 23, 2006, 07:17:21 AM
Change
<?
/* Config Part --------------------------------------------------------------------------------------------------------------*/
$random = true;    
$directory = "home/www/public_html/quote/";    //Put the correct path// 
$quotefile = "randomquote.inc";         //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//
/* End of Config Part -------------------------------------------------------------------------------------------------------*/


to
<?php
/* Config Part --------------------------------------------------------------------------------------------------------------*/
$random = true;  
$directory = "home/www/public_html/quote/";    //Put the correct path//  
$quotefile = "randomquote.inc";        //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//
/* End of Config Part -------------------------------------------------------------------------------------------------------*/





Title: Re: Random Quotes
Post by: crip on February 23, 2006, 09:17:20 PM
This is correct...
Quote
My Current Code (randomquote.php)
<?
/* Config Part --------------------------------------------------------------------------------------------------------------*/
$random = true;      
$directory = "home/www/public_html/quote/";    //Put the correct path// 
$quotefile = "randomquote.inc";           //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//
/* 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]";
?>

Still not got it?
Title: Re: Random Quotes
Post by: Mitch on February 23, 2006, 09:46:46 PM
Nope still not working just getting a blank spot on my forums. Is this supposed to be in the forum folder or in the servers root folder?
Title: Re: Random Quotes
Post by: G6Cad on February 23, 2006, 11:51:38 PM
Got it to work :)

i had to go the other way and use this part, same a Ray i guess?

The quote folder i have in the FORUM folder together with the themes and all the other forum things

//Put this in a phpbox/block//
//*--------------------------------------//*
include "./quote/randomquote.php";
//*--------------------------------------//*


And change the randomquote.php to this

<?php
/* Config Part --------------------------------------------------------------------------------------------------------------*/
$random = true;  
$directory = "./quote/";    //Put the correct path//  
$quotefile = "randomquote.inc";        //Add all quotes in this file in one line//
$quotecountfile = "displayquote.inc";   //This counts quotes, could be optionable if random is set false//
/* End of Config Part -------------------------------------------------------------------------------------------------------*/


So now i can go to bed a feel good about have this working now :)
Title: Re: Random Quotes
Post by: Mitch on February 24, 2006, 12:39:17 AM
Quote from: Ray on February 22, 2006, 03:15:53 PM
Quote from: ÂÃ,»cripÂÃ,« on February 22, 2006, 12:20:04 AM
<p align="center"><? php quotes  ?></p>
or
<center>
<? php quotes
?>
</center>



I fixed it and had to do it in the randomquote.php file

and all the trouble I had and it was just becaue the php after the <? was not their


Thanks for that Ray I had that same problem I do believe and the include statement was wrong. Thanks for the whole centering thing.

And CRIP I GOT IT TOO WORK! MUAHAHA
*cough*cough*
haha
Title: Re: Random Quotes
Post by: crip on February 24, 2006, 12:57:17 AM
You can use your own quotes mitch, one line at a time..the more you have the more random they become.



Title: Re: Random Quotes
Post by: crip on February 24, 2006, 12:58:33 AM
Quotes :

http://lachlan.bluehaze.com.au/deep.html

Title: Re: Random Quotes
Post by: Mitch on February 24, 2006, 01:07:48 AM
Oh that works I was just going to ask members to start donating me some!
Title: Re: Random Quotes
Post by: Gargoyle on February 24, 2006, 02:55:17 AM
LOL!!! Now I can't get it to work...

Went through all the posts and nothing... Probably path related. I will go check some more.. ;D
Title: Re: Random Quotes
Post by: elpvn on April 05, 2006, 06:29:10 AM
See here
Quote from: L1played with this a long time and I know nothing about code but was getting the same error that ray has here, basically showing the code from randomquote.php instead of a quote.  I got it to work by doing this:

$directory = "./quote/";    //Put the correct path// 

and this

include "./quote/randomquote.php";

why that works I have no idea 

maybe something to do with server setting?

great little mod, I love it 

thanks alot
Title: Re: Random Quotes
Post by: Ray on April 05, 2006, 03:15:54 PM
Make aure the PHP in in the file randomquote.php <?php
Title: Re: Random Quotes
Post by: Crip on April 05, 2006, 03:22:52 PM
The Random Quote can be added many different ways actually. ;)
Title: Re: Random Quotes
Post by: dkaye315 on April 23, 2006, 04:49:18 PM
Why is it that something which should be relatively simple isn't?  Had a dickens of a time trying to get this to work.  Finally, created a 2nd phpblock, inserted the exact same code I had been inserting all along and it worked (and then deleted the 1st block).  ??  I was almost at the point of this particular quote:

"If at first you don't succeed, destroy all evidence that you tried."
Title: Re: Random Quotes
Post by: deadpoeticstar on May 04, 2006, 09:16:27 PM
Parse error: parse error, unexpected $ in /home/georgeli/public_html/smf/Sources/Load.php(1609) : eval()'d code(34) : eval()'d code on line 1
thats AFTER i place in this code

ok fixed that....now its not showing

http://georgelittle.2plans.com/smf (its a center block)

could it be because some of my quotes dont fit on one line?
Title: Re: Random Quotes
Post by: URPG on June 01, 2006, 12:11:56 AM
All demos i found on this pages do not work  :'(

Is it because you all removed it and gave up on it???

I'd like a block like this... can't be that difficult? Just need a piece of code that pics a random line from a txt file and spits it out?
Title: Re: Random Quotes
Post by: G6Cad on June 01, 2006, 07:33:26 AM
 i had it just to test this one,and it worked on my board, same on most people that tried this snippet. it worked but arent all that fynny ;)
Title: Re: Random Quotes
Post by: l00p on June 07, 2006, 10:16:20 PM
hey guys.

I'm just wondering how I can format the text in the qoute file, like line break or making some part of the qoute bold or italic etc.

Thx in advance!

l00p,
Title: Re: Random Quotes
Post by: Crip on June 09, 2006, 12:29:52 PM
Quote from: l00p on June 07, 2006, 10:16:20 PM
hey guys.

I'm just wondering how I can format the text in the qoute file, like line break or making some part of the qoute bold or italic etc.

Thx in advance!

l00p,


This one lets you format the Quotes...

http://www.tinyportal.net/smf/index.php?topic=4989.0
Title: Re: Random Quotes
Post by: l00p on June 09, 2006, 12:43:18 PM
It works with this script also, it was me that used BBcodes in stead of the PHP codes "<.br>" "<.b>" etc. My fault :$

Thx for the replay Crip.
Title: Re: Random Quotes
Post by: than on June 09, 2006, 01:10:10 PM
Hi, i have this errors:

http://www.comunidad.than.org.es/index.php?topic=882.msg5254 
2: (null)(): Failed opening 'â€Ã...“RandomQuotephpâ€Ã,' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')
Archivo: /home/thanco/public_html/comunidad/Themes/default/Display.template.php (eval?)
LÃÆ'Ã,­nea: 1


I test with phpquotes, but same error
Title: Re: Random Quotes
Post by: gerrymo on June 09, 2006, 01:29:55 PM
Shouldn't RandomQuotephp read RandomQuote.php ??
Title: Re: Random Quotes
Post by: than on June 09, 2006, 02:18:18 PM
Solved in other message,, thanks to all.  :D
Title: Re: Random Quotes
Post by: Maviarab on June 09, 2006, 11:37:53 PM
Hi all,

I know its not a snippet as such, but regarding the random quotes i use this

http://feeds.feedburner.com/brainyquote/QUOTEBR

From http://www.brainyquote.com/quotes/type/type_celebrity.html

Its along the same lines only not customisable...still very good though

Hope it helps  :)

Title: Re: Random Quotes
Post by: Crip on June 12, 2006, 12:33:53 PM
Thanks for the good link. ;)
Title: Re: Random Quotes
Post by: brianjw on February 03, 2007, 03:37:05 AM
Works like a charm :D
Title: Re: Random Quotes
Post by: digisubs on February 19, 2007, 02:00:50 PM
ive got pretty extensive quotes and TP keeps on truncating it at line 463. so i always get an unexpected $end error on the phpbox. is there a way for the php code to call an external text file so i can have as many random quotes as i want?
Title: Re: Random Quotes
Post by: Crip on February 19, 2007, 02:16:22 PM
dig,
my quotes are in an external - randomquotes.inc file..add as many as I want..up to 700 hundred or so now..
Title: Re: Random Quotes
Post by: brianjw on February 19, 2007, 02:25:05 PM
lol crip. u keep changing ur username to weird characters :D
Title: Re: Random Quotes
Post by: Crip on February 19, 2007, 02:27:15 PM
crookiedeee like me.. :D
Title: Re: Random Quotes
Post by: Chelle on May 13, 2007, 08:57:38 PM
I tried all the suggestions here to get this to work.  What worked for me was having my path as

../forum_folder/quote/

and the include to look like this:

include "../forum_folder/quote/randomquote.php";

and adding in the php after the <? at the beginning in randomquote.php.  After that, it all played nice.  Thank crip, nice lil snippet :P
Title: Re: Random Quotes
Post by: tomtom9800 on August 13, 2007, 05:29:54 AM
IS there anyway to delay the quotes to lets say a day before a new one is generated?
Title: Re: Random Quotes
Post by: JPDeni on August 13, 2007, 03:13:54 PM
No. Not if you're doing random quotes. You could set up the quotes differently so that there was a different quote for each day or would cycle through the quotes, no matter how many there are.
Title: Re: Random Quotes
Post by: Crip on August 13, 2007, 04:17:11 PM
could just add one each day..Lol .. remove the one you already have & add 1 new one..coarse you'd need to do that daily..
Title: Re: Random Quotes
Post by: China-Garten on December 31, 2007, 12:39:29 PM
QuoteNo. Not if you're doing random quotes. You could set up the quotes differently so that there was a different quote for each day or would cycle through the quotes, no matter how many there are.

So how would you do that? I want to have one quote each day, not random, but one specifiic,  that I assign for that day. The deal is: I don't want to have to get online to change the quote dayly, rather for a whole week or month at once. ;D
Title: Re: Random Quotes
Post by: JPDeni on December 31, 2007, 02:00:07 PM
I responded in the other topic where you asked that question.