Random quote in header

Temporary forum to obtain support for MODs/Styles while phpbb.com is down
Locked
Mplius
Registered User
Posts: 5
Joined: Mon Feb 02, 2009 4:13 pm
Location: Lithuania
Contact:

Random quote in header

Post by Mplius »

So, basically I am making a new style for my community. One of the features I want, is a random quote phrase in header.
Image

I am not php programmer nor I am really experienced in this. But I can manage to edit something a little. So, I found a random phrase php script and I want to somehow put it in my template.

Here's the script I used: http://clarksco.com/?p=13
And here is how it works in my website http://www.animecentras.lt/forumas/citatos/index.php

Here's my overall header:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="{S_CONTENT_DIRECTION}" lang="{S_USER_LANG}" xml:lang="{S_USER_LANG}">
<head>

<meta http-equiv="content-type" content="text/html; charset={S_CONTENT_ENCODING}" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-language" content="{S_USER_LANG}" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="resource-type" content="document" />
<meta name="distribution" content="global" />
<meta name="copyright" content="2000, 2002, 2005, 2007 phpBB Group" />
<meta name="keywords" content="" />
<meta name="description" content="{SITE_DESCRIPTION}" />
{META}
<title>{SITENAME} &bull; <!-- IF S_IN_MCP -->{L_MCP} &bull; <!-- ELSEIF S_IN_UCP -->{L_UCP} &bull; <!-- ENDIF -->{PAGE_TITLE}</title>

<script type="text/javascript">
// <![CDATA[
	var jump_page = '{LA_JUMP_PAGE}:';
	var on_page = '{ON_PAGE}';
	var per_page = '{PER_PAGE}';
	var base_url = '{A_BASE_URL}';
	var style_cookie = 'phpBBstyle';
	var style_cookie_settings = '{A_COOKIE_SETTINGS}';
	var onload_functions = new Array();
	var onunload_functions = new Array();

	<!-- IF S_USER_PM_POPUP -->
		if ({S_NEW_PM})
		{
			var url = '{UA_POPUP_PM}';
			window.open(url.replace(/&/g, '&'), '_phpbbprivmsg', 'height=225,resizable=yes,scrollbars=yes, width=400');
		}
	<!-- ENDIF -->

	/**
	* Find a member
	*/
	function find_username(url)
	{
		popup(url, 760, 570, '_usersearch');
		return false;
	}

	/**
	* New function for handling multiple calls to window.onload and window.unload by pentapenguin
	*/
	window.onload = function()
	{
		for (var i = 0; i < onload_functions.length; i++)
		{
			eval(onload_functions[i]);
		}
	}

	window.onunload = function()
	{
		for (var i = 0; i < onunload_functions.length; i++)
		{
			eval(onunload_functions[i]);
		}
	}

// ]]>
</script>
<script type="text/javascript" src="{T_TEMPLATE_PATH}/styleswitcher.js"></script>
<script type="text/javascript" src="{T_TEMPLATE_PATH}/forum_fn.js"></script>

<link href="{T_THEME_PATH}/print.css" rel="stylesheet" type="text/css" media="print" title="printonly" />
<link href="{T_STYLESHEET_LINK}" rel="stylesheet" type="text/css" media="screen, projection" />

<link href="{T_THEME_PATH}/normal.css" rel="stylesheet" type="text/css" title="A" />
<link href="{T_THEME_PATH}/medium.css" rel="alternate stylesheet" type="text/css" title="A+" />
<link href="{T_THEME_PATH}/large.css" rel="alternate stylesheet" type="text/css" title="A++" />

<!-- IF S_CONTENT_DIRECTION eq 'rtl' -->
	<link href="{T_THEME_PATH}/bidi.css" rel="stylesheet" type="text/css" media="screen, projection" />
<!-- ENDIF -->

</head>

<body id="phpbb" class="section-{SCRIPT_NAME} {S_CONTENT_DIRECTION}">

<div id="wrap">
    <div class="headerbar">
            <div class="logo">

                     <div style="float: left;">
                          <a href="{U_INDEX}" title="{L_INDEX}" class="headerlink">
                                
                          </a>
                     </div>
                     <div onclick="javascript: window.location = '{U_INDEX}';" style="float: left; cursor: pointer;">

                                <h1>{SITENAME}</h1>
                                <br />
                                <span class="description">
								
								HERE I NEED MY QUOTES!!!!!!!
                               							
								</span>
                     </div>
            </div>
	</div>


            <div class="navbar">

			<ul class="linklist navlinks">
				<li class="icon-home"><b><a class="white" href="{U_INDEX}" accesskey="h">{L_INDEX}</a> <!-- BEGIN navlinks --> <strong>&#8249;</strong> <a class="white" href="{navlinks.U_VIEW_FORUM}">{navlinks.FORUM_NAME}</a><!-- END navlinks --></b></li>
				<li class="rightside"><a href="#" onclick="fontsizeup(); return false;" class="fontsize" title="{L_CHANGE_FONT_SIZE}">{L_CHANGE_FONT_SIZE}</a></li>
				<!-- IF U_EMAIL_TOPIC --><li class="rightside"><a href="{U_EMAIL_TOPIC}" title="{L_EMAIL_TOPIC}" class="sendemail">{L_EMAIL_TOPIC}</a></li><!-- ENDIF -->
				<!-- IF U_EMAIL_PM --><li class="rightside"><a href="{U_EMAIL_PM}" title="{L_EMAIL_PM}" class="sendemail">{L_EMAIL_PM}</a></li><!-- ENDIF -->
				<!-- IF U_PRINT_TOPIC --><li class="rightside"><a href="{U_PRINT_TOPIC}" title="{L_PRINT_TOPIC}" accesskey="p" class="print">{L_PRINT_TOPIC}</a></li><!-- ENDIF -->
				<!-- IF U_PRINT_PM --><li class="rightside"><a href="{U_PRINT_PM}" title="{L_PRINT_PM}" accesskey="p" class="print">{L_PRINT_PM}</a></li><!-- ENDIF -->
    		</ul>

			<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
			<ul class="linklist leftside">
				<li  class="icon-ucp">
					<a class="white" href="{U_PROFILE}" title="{L_PROFILE}" accesskey="u">{L_PROFILE}</a>
				<!-- IF S_DISPLAY_PM --> (<a class="white" href="{U_PRIVATEMSGS}">{PRIVATE_MESSAGE_INFO}</a>)<!-- ENDIF --> &bull;
					<a class="white" href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a>
					<!-- IF U_RESTORE_PERMISSIONS --> &bull;
					<a class="white" href="{U_RESTORE_PERMISSIONS}">{L_RESTORE_PERMISSIONS}</a>
					<!-- ENDIF -->
				</li>
			</ul>
			<!-- ENDIF -->

			<ul class="linklist rightside">
				<li class="icon-faq"><a class="white" href="{U_FAQ}" title="{L_FAQ_EXPLAIN}">{L_FAQ}</a></li>
				<!-- IF not S_IS_BOT -->
					<!-- IF S_DISPLAY_MEMBERLIST --><li class="icon-members"><a class="white" href="{U_MEMBERLIST}" title="{L_MEMBERLIST_EXPLAIN}">{L_MEMBERLIST}</a></li><!-- ENDIF -->
					<!-- IF not S_USER_LOGGED_IN and S_REGISTER_ENABLED --><li class="icon-register"><a class="white" href="{U_REGISTER}">{L_REGISTER}</a></li><!-- ENDIF -->
					<li class="icon-logout"><a class="white" href="{U_LOGIN_LOGOUT}" title="{L_LOGIN_LOGOUT}" accesskey="l">{L_LOGIN_LOGOUT}</a></li>
				<!-- ENDIF -->
			</ul>

		</div>

	<a name="start_here"></a>
	<div id="page-body">

		 <!-- IF S_BOARD_DISABLED and S_USER_LOGGED_IN and (U_MCP or U_ACP) -->
		<div id="message" class="rules">
			<div class="inner"><span class="corners-top"><span></span></span>
				<strong>{L_INFORMATION}:</strong> {L_BOARD_DISABLED}
			<span class="corners-bottom"><span></span></span></div>
		</div>
		<!-- ENDIF -->
My style is based on SkyBlue. Forum version 3.0.4. So, how can I make the script work? Thanks for help :)
http://www.animecentras.lt - lithuanian anime community.

Phox
Registered User
Posts: 6
Joined: Thu Jul 24, 2008 2:06 pm

Re: Random quote in header

Post by Phox »

You're asking for a modification, not support, but I'll guide you in the right direction.

What you'll need to do is put the script in the page_header function in functions.php. Then you'll need to edit the variable to be outputted to the template.

The code for the template is

Code: Select all

$template->assign_vars(array(
'RANDOM_QUOTE' => $theQuote . '- <a href="' . $theLink . '" target="_blank">' . $theRef . '</a>',
));
From that code(for the modification), you'll only need this.

Code: Select all

      $dbFileName = array("political.db","religious.db");
/*
The variable $dbFileName is an array of the paths to the quote databases.  The example above indicates that the database files are in the same directory as the script.  If you put them in a different directory, say quotes/, then this variable would look like:
$dbFileName = array("quotes/political.db","quotes/religious.db");
if you want to pull from one database, the array should look like:
$dbFileName = array("political.db");
*/
	$numDB = count($dbFileName);
/*
The variable $numDB informs the script how many quote databases to pull from.
*/
      $quoteType = 0;
/*
The variable $quoteType determines the type of quote generation.
quoteType = 0 displays a new random quote each time the page is loaded.
quoteType = 1 displays a new random quote every 60 minutes.
quoteType = 2 displays a new random quote every 24 hours.
quoteType = 3 displays a new random quote once every 7 days.
Settings 1, 2 & 3 are handled by storing a cookie. 
Use the included "del_cookie.php" script to delete the cookie while you are testing the script.
*/
      if ($numDB == 1)
      {
            $filename = $dbFileName[0];
      }else{
            $ranDB = rand(1, $numDB);
            $filename = $dbFileName[$ranDB-1];
      }
/*
This conditional Statement if ($numDB == 1){.... is picking the database from which to pull the quotes. If the variable $numDB is set to 1 it pulls the first db in the array.  You will notice that $dbFileName is set to 0.  This is because most languages consider 0 to be the first number when counting.
*/
      $lines = file($filename);
      $numQuotes = count ($lines);

      if ($quoteType == 0)
      {
            $ranNum = rand(1, $numQuotes);
      }elseif ($quoteType == 1){
		if (isset($_COOKIE['quoteNum'])) 
            {
                  $ranNum = $_COOKIE['quoteNum'];
            } else {
    		      $ranNum = rand(1, $numQuotes);
                  setcookie("quoteNum", $ranNum, time()+60*60);// One Hour
            }
	}elseif ($quoteType == 2){
		if (isset($_COOKIE['quoteNum'])) 
            {
                  $ranNum = $_COOKIE['quoteNum'];
            } else {
                  $ranNum = rand(1, $numQuotes);
                  setcookie("quoteNum", $ranNum, time()+60*60*24); //Twenty-four Hours
            }
	}elseif ($quoteType == 3){
		if (isset($_COOKIE['quoteNum'])) 
            {
                  $ranNum = $_COOKIE['quoteNum'];
            } else {
    		      $ranNum = rand(1, $numQuotes);
                  setcookie("quoteNum", $ranNum, time()+60*60*24*7); // Seven Days
            }
      }
/*
This conditional Statement if ($quoteType == 0){.... is determining the interval at which you want the quotes displayed.  This feature uses the Set Cookie function.  Which places a cookie in the users browser.
*/
      $line = $lines[$ranNum-1];
      $element = explode("::",$line);
      $theQuote = $element[0];
      $theRef = $element[1];
      $theLink = $element[2];
This should go before that template code, but after function page_header () { in the functions.php file.

Then add {RANDOM_QUOTE} in your template (overall_header.html) wherever you want it. :)

Mplius
Registered User
Posts: 5
Joined: Mon Feb 02, 2009 4:13 pm
Location: Lithuania
Contact:

Re: Random quote in header

Post by Mplius »

Thank you very much for guidance, I guess I'll try it.
One more question. Is it possible to do this, only modyfying template files? Since when I update everything, I'll need to do this (in functions.php) yet again.
http://www.animecentras.lt - lithuanian anime community.

bolverk
I've been banned
Posts: 280
Joined: Mon Feb 02, 2009 5:39 pm

Re: Random quote in header

Post by bolverk »

Scroll down to the PHP section of this document.

Mplius
Registered User
Posts: 5
Joined: Mon Feb 02, 2009 4:13 pm
Location: Lithuania
Contact:

Re: Random quote in header

Post by Mplius »

Thank you very much, I edited functions.php
Works like a charm ^^

Image
http://www.animecentras.lt - lithuanian anime community.

parasolx
Registered User
Posts: 10
Joined: Mon Feb 02, 2009 3:07 am

Re: Random quote in header

Post by parasolx »

based in this script, how those *.db files would likely look?

what format should it be?

what coding to make it functional?

cause i see in the function.php, in the template said this:
Phox wrote:$template->assign_vars(array(
'RANDOM_QUOTE' => $theQuote . '- <a href="' . $theLink . '" target="_blank">' . $theRef . '</a>',
));
mean, it must be an array of $theQoute, $theLink, and $theRef in *.db files. can sumebody shows some examples.

Mplius
Registered User
Posts: 5
Joined: Mon Feb 02, 2009 4:13 pm
Location: Lithuania
Contact:

Re: Random quote in header

Post by Mplius »

Since it works for me, here's an example for *.db files how I made them work.

Code: Select all

Faye faye smoke smoke, faye faye puff puff! Yay! - Ed::(Cowboy Bebop)::http://www.animecentras.lt/forumas/viewtopic.php?f=5&t=398&start=0&st=0&sk=t&sd=a#p6098
And what's the real lesson? Don't leave things in the fridge.<br />- Spike Spiegel::(Cowboy Bebop)::http://www.animecentras.lt/forumas/viewtopic.php?f=5&t=398&start=0&st=0&sk=t&sd=a#p6098
You may call me whatever you wish - but I'm taking your cake. - L::(Death Note)::http://www.animecentras.lt/forumas/viewtopic.php?f=5&t=10&p=12#p12
So, basically you need one quote in one line. One line should look like this:

Code: Select all

[your quote]::[link name]::[link to sth]
And that's all.
http://www.animecentras.lt - lithuanian anime community.

Locked