I would like to continue using this script since I already have the specific quotes in the file, and would like to emplement it on several s9y sites.
You can see it in action
here.
Thank you for the help.
Code: Select all
<script language="php">
/* *****************************************************************
PHP-DISPLAYER V-2.02 (c) 2002 Peter Kerl
Tips, Tags, Quotes and Pics for Webpages. Examples
and more Quote-Files you will find at:
http://passepartout.peterkerl.de
***************************************************************** */
//------------------------------------------------------------------
/* DEFAULT-SETTINGS */
// please don't forget to put a link to my site
$displayNo = 1; // Number of displayed tags/pics
$file1 = "inc/quotes.txt"; // Files containing your tags
// $file2, $file3 for further displays, otherwise $file1 is default
$mode1 = "random"; // "sequence", "random" or "periodical"
// $mode2, $mode3 for further displays, otherwise $mode1 is default
$period1 = "wday"; // the measure for changes in "periodical"-mode.
/* "wday" = day of week (7); "mday" = day of month (31);
"yday" = day of year (365); "hours" = hour of day (24);
"weeks" = week of year (53) */
// $period2, $period3 for further displays
$weekstart1 = "sun"; //only in "weeks"-period. Determines the day of change.
/* "sun", "mon", "tue", "wed", "thur", "fri", "sat" */
// $weekstart2, $weekstart3 etc.
// general settings:
$sep = "%%"; // Signs used to separate the tags, according to your tag-files.
$lineBreak = 1; // automatic Linebreaks for simple text-displays,
// otherwise set $lineBreak = 0
$startNo = 1; // only in sequence-modus
$deleteRepeats = 50; // only random-modus. 10 times without duplicates
//-------------------------------------------------------------------
/* The CODE, do only change, if you know what you do */
// overrule default-settings:
if (isset($o_displayNo)) $displayNo = $o_displayNo;
if (isset($o_lineBreak)) $lineBreak = $o_lineBreak;
if (isset($o_sep)) $sep = $o_sep;
if (isset($o_startNo)) $startNo = $o_startNo;
if (isset($o_deleteRepeats)) $deleteRepeats = $o_deleteRepeats;
$indexdata = ""; $randomdata = ""; $data = "";
for ($a=1; $a<=$displayNo; $a++) {
$display = "display$a";
$file = "file$a";
$o_file = "o_file$a";
$mode = "mode$a";
$o_mode = "o_mode$a";
$period = "period$a";
$o_period = "o_period$a";
$weekstart = "weekstart$a";
$o_weekstart = "o_weekstart$a";
$index = "index$a";
$x = "x$a";
$x_sum = "x_sum$a";
if (isset($$o_file)) $$file = $$o_file;
if (!isset($$file)) $$file = $file1;
if (isset($$o_mode)) $$mode = $$o_mode;
if (!isset($$mode)) $$mode = $mode1;
$tags = FileToArray($$file);
if (is_array($tags)) {
if ($$mode == "sequence") {
if (! isset($$index)) {$$index = $startNo - 1;}
if ($$index < 0 || $$index >= count($tags)) {$$index = 0;}
${$x}[] = $$index;
$$display = formatText($tags[$$index]);
$$index++;
}
elseif ($$mode == "random") {
srand ((double) microtime() * 10000000);
if (! isset($$index)) {$$index = getRKey($tags);}
${$x}[] = $$index;
$$display = formatText($tags[$$index]);
if ($deleteRepeats > count($tags)) {$deleteRepeats = count($tags);}
if (count(${$x}) >= $deleteRepeats) {${$x} = array($$index);}
$$index = deleteReps($tags, $$x);
}
else { // periodical
if (isset($$o_period)) $$period = $$o_period;
if (!isset($$period)) $$period = $period1;
if (isset($$o_weekstart)) $$weekstart = $$o_weekstart;
if (!isset($$weekstart)) $$weekstart = $weekstart1;
$t_stamp = time();
$arrDate = getdate($t_stamp);
if ($$period == "weeks") $number = getWeek($$weekstart);
else $number = $arrDate[$$period];
if ($$period == "mday" || $$period == "hours") $number--;
$max = count($tags);
if ($number >= $max) {$number %= $max;}
elseif ($number < 0) {$number = $max - 1;}
$$display = formatText($tags[$number]);
}
}
else {
$$x = array(0);
$$display = "File \"${$file}\" not found";
}
$$x_sum = "";
if ($deleteRepeats > 1 && $$mode == "random") {
reset ($$x);
while (list(, $value) = each ($$x)) {
${$x_sum} .= "&x$a%5B%5D=$value";
}
$randomdata .= ${$x_sum};
}
if ($a == 1) $indexdata = "index$a=${$index}";
else $indexdata .= "&index$a=${$index}";
} // end for
$data = "?$indexdata$randomdata";
function FileToArray($filename) {
global $sep;
if (file_exists($filename)) {
if (filesize($filename) == 0) return 0;
$fcontent = join ('', file ($filename));
return explode ($sep, $fcontent);
}
return 0;
}
function deleteReps($tags, &$x) {
$loops = 0;
$maxLoops = 15;
do {
$ndx = getRKey($tags);
$found = 0;
$loops++;
reset ($x);
while (list(, $value) = each ($x)) {
if ($ndx == $value) {
$found = 1;
break;
}
}
} while ($found == 1 && $loops < $maxLoops);
return $ndx;
}
function getRKey($arr){
$c = count($arr) - 1;
return rand(0, $c);
}
function formatText($text) {
global $lineBreak;
$text = trim($text);
if ($lineBreak == 0) return $text;
$text = str_replace("\r\n\r\n", "<p>", $text);
$text = str_replace("\r\n", "<br>", $text);
$text = str_replace("\n\n", "<p>", $text);
$text = str_replace("\n", "<br>", $text);
$text = str_replace("\t", " ", $text);
$text = str_replace(" ", " ", $text);
return $text;
}
function getWeek($wstart) {
global $arrDate;
$YD = $arrDate["yday"];
$Y7 = ($YD % 7) + 1;
$YD++;
$WD = $arrDate["wday"];
if ($wstart == "sun") $wstart = 0;
elseif ($wstart == "mon") $wstart = 1;
elseif ($wstart == "tue") $wstart = 2;
elseif ($wstart == "wed") $wstart = 3;
elseif ($wstart == "thur") $wstart = 4;
elseif ($wstart == "fri") $wstart = 5;
elseif ($wstart == "sat") $wstart = 6;
$WD = $WD - $wstart;
if ($WD < 0) $WD += 7;
$WD++;
$week = ceil($YD / 7);
if ($WD < $Y7) $week += 1;
return $week - 1;
}
</script>