Page 1 of 1

random_quote tag

Posted: Thu Sep 13, 2007 5:36 am
by scsl
Hi!

I am making a website requiring different sets of quotes to appear on different pages. For example, on the home page, I would like that a set of quotes randomly be displayed at a corner.  Then in another section, another set of quotes relevant to that section be displayed randomly in a particular location.  The random_quote tag, however, can only be used for one set, since it accepts only one filename: quotes.txt, which must be placed at the root directory, and does not accept any parameter.  May I request that the functionality of this tag be expanded to accept a text filename (includes pathname) and a webpage id or alias?    Many thanks!  :)

Re: random_quote tag

Posted: Thu Sep 13, 2007 2:37 pm
by cyberman
Search is your friend - have you tried this?

http://dev.cmsmadesimple.org/projects/randomquote/

Re: random_quote tag

Posted: Fri Sep 14, 2007 3:07 am
by scsl
Yes, that's the one I was refering to when I said:

   
The random_quote tag, however, can only be used for one set, since it accepts only one filename: quotes.txt, which must be placed at the root directory, and does not accept any parameter.  May I request that the functionality of this tag be expanded to accept a text filename (includes pathname) and a webpage id or alias?    Many thanks!
    I need random_quote tag  to accept a filename (with path) as a parameter.  As of now, it accepts a hard-coded file named "quote.txt" that must reside at the root directory.

    I understand its php code but I don't know how to modify it to accept parameter for the smarty tag. I could study it but it will take time.  If cmsms team can do it, I'd appreciate it!    :)

Re: random_quote tag

Posted: Fri Sep 14, 2007 3:56 am
by calguy1000
This is custom module development as nothing like this exists yet (nobody's written it yet).  I wrote the first random quote tag, and it was one of my first CMS projects.  it's outdated now.

Might I suggest, that if you have some available funds, you sponsor Ted, or one of the other dev team members to write such a module.  This would satisfy your needs, contribute to the CMS community, and compensate a developer for relinquishing his (non work time?) time to do development on a task that he's not necessarily focussed on at the moment.

Just my $0.02

Re: random_quote tag

Posted: Fri Sep 14, 2007 3:06 pm
by cyberman
scsl wrote:     I understand its php code
OK. You said, you want a solution. You said, you understand php code. Try the attached files. Delete .txt before.

It's a Smarty plugin (not CMSms!) for showing .csv files with templates and has an option to show values randomly.

WARNING: There's NO manual inside !!!

Re: random_quote tag

Posted: Sat Sep 15, 2007 2:02 am
by scsl
Thank you, calguy.  Thank you, cyberman for the attachments.  Really appreciate it.  It's going to take me a while to read and understand it.  But guess what, I tried my hand on the php code of that plug-in tag (function.random_quote.php).  It works according to what I want.  I added two lines, and commented out one line.

function smarty_cms_function_random_quote($params, &$smarty) {
$delim = "\n";

// $quotefile points to the file that holds the actual quotes

$quotefile = $params['quotefile'];          /* added  */
if (file_exists($quotefile)) {                  /* added  */


// $quotefile = "quotes.txt";        /* commented out */

$fp = fopen($quotefile, "r");
$contents = fread($fp, filesize($quotefile));
$quote_arr = explode($delim,$contents);
fclose($fp);
srand((double)microtime()*1000000);
$quote_index = (rand(1, sizeof($quote_arr)) - 1);
$herequote = $quote_arr[$quote_index];
return $herequote;
}                                                      /* added  */

}


Now, if there is no bug, radom_quote accepts a parameter which is the filename of the quote file with its pathname included:

eg, in the same website,
  in "musicians" section:  {random_quote quotefile='uploads/quotesfiles/quotesmusicians.txt'}
  in "poets" section:  {random_quote quotefile='uploads/quotesfiles/quotespoets.txt'}
  in "sages" section:  {random_quote quotefile='uploads/quotesfiles/quotessages.txt'}

Today is my happy day!!    :)