wkitty42
2nd of August 2004 (Mon), 13:02
i've the snippetdemo and snippets code files in my gallery directory... when i try to access snippetdemo.php, all i get back is a clean white page with several horizontal bars... the only change i made to the snippetdemo code was to have it reference my site instead of the domain/url that was in it...
what am i missing??
wkitty42
2nd of August 2004 (Mon), 16:03
ok, figured it out... now to figure out why it is doing what it is doing... here's the situation...
my server uses .htaccess to block access to the site if the referer and the useragent are both blank.
my system doesn't seem to like php include() being addressed directly to the local filesystem.
putting the snippets.php file in the defined php include directory doesn't work as it should.
php doesn't seem to set a referer or a useragent when doing an include() via http methods.
the combination of the above 4 situations prevented the snippets from working... i ended up adding the setting to display error messages and was finally able to see my 403.1 errorcode which i setup for the no useragent no referer situation... that lead me to my .htaccess file to try to find a workaround... the /only/ workaround i was able to find was to specify my server's ip address in the exclusion list...
now i'm off to the support group for my setup to figure out why direct filesystem include() access isn't working :x i'm sure that its going to have something to do with non-*nix ways since everything i run was ported to my chosen operating system from *nix... it could be something to do with \'s vs /'s, the use of drive letters (ie: c: - i: here) or the fact that things are spread across several drive instead of residing all on one drive in one tree... [diety] knows that i tried all combinations before whacking in the .htaccess hole to let the system access itself... that'll be changing ASAP once i figure out why this problem is happening...
wkitty42
2nd of August 2004 (Mon), 16:20
man, i just luuurve fast and active support groups :D
ok, here it is... when you
include("snippets.php?get=latest_galleries");
the php looks for a file named "snippets.php?get=latest_galleries'" (without the quotes) in the local filesystem... so, to do this without using http includes, you have to set the variables first and then include just the filename with no parameters... like this...
<?php
ini_set("allow_url_fopen",TRUE);
ini_set("display_errors",TRUE);
$get="latest_galleries";
include 'snippets.php';
?>
you may or may not need the "allow_url_fopen"... php's newer than 4.0.3 default to it being TRUE... so unless its been manually turned off by your host admin, you shouldn't need that setting... the "display_errors" one is so you can see where the problems are... you likely don't need that one, either... especially after you get things working as desired ;)
so, there it is... a combination of several factors can surely mess up a good day... i know that mine is totally shot... now its time to go get a beverage and relax a while ;)
wkitty42
12th of August 2004 (Thu), 16:51
no, i'm not crazy or talking to myself... t'would be nice if others had responded to this thread, but that's ok :?
<?php
ini_set("allow_url_fopen",TRUE);
ini_set("display_errors",TRUE);
$get="latest_galleries";
include 'snippets.php';
?>
there is a problem with the snippets code when using the above format and not using the URL retrieval method... some sites, like mine, are restrictive in that they do not allow blank user agents and/or blank referrers to access their site... PHP allows for one to include scripts from the local drive(s) or via URL... the original snippets code was written to use the URL method which fails on sites like mine... so, i undertook to figure out why and what it would take to make it work...
the first thing i ran into is that the snippets code defines a function... when trying to include the snippets code from the local drive, as above, multiple times in one page, i was getting an error aboue trying to redefine that function... the fix for that is to move that function to another file and include_once in the snippets code...
i ran into a few other problems and also incorporated the latest_exhibit mod... in doing so, i uncovered several bugs... i've modified the snippets code to take care of these bugs and use a few enhancements... i post all the code for your use... pekka, feel free to use this in the next release if it is still compatible...
snippets.php<?php
//For EE 1.5 RC 4 - modified by mfl - 12 Aug 2004
include ("toroot.php");
include ($toroot . "add/connect.php");
include_once ($toroot . "language.php");
include_once ($toroot . "slashwork.php");
$getlang = $toroot . "languages/" . $lang . "/global.php";
include_once($getlang);
ini_set("allow_url_fopen",TRUE);
// load ee_print_thumbs function
@require_once ("ee_snip_func.php");
// get vars
if (isset ($HTTP_GET_VARS['exhibition'])) {
$exhibition = $HTTP_GET_VARS['exhibition'];
}
if (isset ($HTTP_GET_VARS['pass'])) {
$pass = rawurldecode($HTTP_GET_VARS['pass']);
}
if (isset ($HTTP_GET_VARS['amount'])) {
$amount = intval($HTTP_GET_VARS['amount']);
}
if (isset ($HTTP_GET_VARS['get'])) {
$get = $HTTP_GET_VARS['get'];
}
if (isset ($HTTP_GET_VARS['thumbsize'])) {
$thumbsize = $HTTP_GET_VARS['thumbsize'];
}
if (isset ($HTTP_GET_VARS['border'])) {
$border = $HTTP_GET_VARS['border'];
}
if (isset ($HTTP_GET_VARS['bordercolor'])) {
$bordercolor = $HTTP_GET_VARS['bordercolor'];
}
if (isset ($HTTP_GET_VARS['viewas'])) {
$viewas = $HTTP_GET_VARS['viewas'];
}
if (isset ($HTTP_GET_VARS['excludecategory'])) {
$excludecategory = $HTTP_GET_VARS['excludecategory'];
}
if (isset ($HTTP_GET_VARS['includecategory'])) {
$includecategory = $HTTP_GET_VARS['includecategory'];
}
if (isset ($HTTP_GET_VARS['hspace'])) {
$hspace = $HTTP_GET_VARS['hspace'];
}
if (isset ($HTTP_GET_VARS['vspace'])) {
$vspace = $HTTP_GET_VARS['vspace'];
}
// set default vars if not already set
if (!isset($pass)) {
$pass = "public";
}
if (!isset($thumbsize)) {
$thumbsize = "thumb";
}
if (!isset($border)) {
$border = "0";
}
if (!isset($bordercolor)) {
$bordercolor = "000000";
}
if (!isset($amount)) {
$amount = "5";
}
if (!isset($excludecategory)) {
$excludecategory = "";
}
if (!isset($includecategory)) {
$includecategory = "";
}
if (!isset($viewas)) {
$viewas = "text";
}
if (!isset($hspace)) {
$hspace = "2";
}
if (!isset($vspace)) {
$vspace = "2";
}
// bugfix - added this_is_index and moved fetchsettings up above next if {} statement
$this_is_index = "";
include_once ($toroot . "fetchsettings.php");
// bugfix for $exhibtion not being set or being set to ""
// forces exhibition to be set to all combined instead of
// the first available exhibit
if (!isset ($exhibition) || $exhibition == "") {
//include ("add/allowedexhibitions_sql.php");
//@$valid = $allowedexhibs[0][0];
//$exhibition=$valid;
$exhibition = $all_exhibitions_combined;
}
$s_ee_html_root = $s_galleryroot;
//commented out for $exhibition=latest_exhibit mod...
//if ($exhibition == "all") $exhibition = $all_exhibitions_combined;
//$exhib_where = "";
//if ($exhibition != $all_exhibitions_combined) {
// $exhib_where = " AND ee_exhibition.ee_exhibition_id = {$exhibition} ";
//}
//Begin latest_exhibit mod - bugfixed and rewritten to correct error with
// $exhib_where being set and messing up latest_photos and random_photos
//keyword renamed to latest_exhibit instead of latest_ex
$exhib_where = "";
if ($exhibition == "2147483647" || $exhibition == "all") {
$exhibition = $all_exhibitions_combined;
// because $exhibition never == "all" at this point
// the function $exhibition = $all_exhibitions_combined makes $exhibition be 7777777, this needs to be here
// bugfix - if exhibition is not set, fetchsettings, if used, forces it to 2147483647
} elseif ($exhibition == "latest_exhibit") {
// if $exhibition == "latest_exhibit", get highest (max_id) numbered exhibition
$query = "Select MAX(ee_exhibition_{$lang}.ee_exhibition_id) AS max_id
FROM ee_exhibition_{$lang}, ee_exhibition
WHERE ee_exhibition.ee_exhibition_pass = 'public'
AND ee_exhibition.ee_exhibition_id = ee_exhibition_{$lang}.ee_exhibition_id";
$result = mysql_query($query);
if (!$result) {
print mysql_error();
}
$result_row = mysql_fetch_assoc($result);
$max_id = $result_row['max_id'];
$exhibition = $max_id;
$exhib_where = " AND ee_exhibition.ee_exhibition_id = {$max_id}";
}
if ($exhibition != $all_exhibitions_combined) {
$exhib_where = " AND ee_exhibition.ee_exhibition_id = {$exhibition}";
}
// end mod
$catfrom = "";
$catwhere = "";
$catwhere_end = "";
$orlist = "";
$betweenors = "";
$exlorlist = "";
$ors = array();
$exlors = array();
if ($includecategory != "" OR $excludecategory != "") {
$catwhere_end = ") ";
$catfrom = "ee_category_{$lazylang},
ee_photo_to_category,";
$catwhere = "
AND ee_photo_to_category.ee_category_id = ee_category_{$lazylang}.ee_category_id
AND ee_photo_to_category.ee_photo_id = ee_photo.ee_photo_id AND (
";
}
if ($includecategory != "") {
$orlist = "";
$inccats = explode("|",$includecategory);
//ee_print_array($inccats);
foreach ($inccats as $key) {
$cat = trim($key);
$ors[] .= " ee_photo_to_category.ee_category_id = '{$cat}' ";
}
$orlist = implode(" OR ",$ors);
}
$exlcatfrom = "";
if ($excludecategory != "") {
$exlorlist = "";
$exlcats = explode("|",$excludecategory);
//ee_print_array($exlcats);
foreach ($exlcats as $key) {
$cat = trim($key);
$exlors[] .= " ee_photo_to_category.ee_category_id <> '{$cat}' ";
}
$exlorlist = implode(" AND ",$exlors);
$exlorlist = " (" . $exlorlist . ")";
}
$betweenors = "";
if (@$orlist != "" AND @$exlorlist != "") {
$betweenors = " OR ";
}
if ($get == "latest_galleries") {
$exhibs_sql = "
SELECT
ee_exhibition_{$lang}.ee_exhibition_name,
ee_exhibition_{$lang}.ee_exhibition_id
FROM
ee_exhibition_{$lang},
ee_exhibition
WHERE
ee_exhibition.ee_exhibition_pass = '{$pass}'
AND ee_exhibition.ee_exhibition_id = ee_exhibition_{$lang}.ee_exhibition_id
ORDER BY
ee_exhibition_{$lang}.ee_exhibition_id DESC
LIMIT {$amount}
";
$exhibs = mysql_query($exhibs_sql);
//print nl2br($exhibs_sql);
if (!$exhibs) {
print mysql_error();
}
}
if ($get == "latest_photos") {
$latest_sql =
"
SELECT
ee_photo.ee_photo_id,
ee_photo_{$lazylang}.ee_photo_header,
ee_photo.ee_photo_exif_datetime,
ee_exhibition.ee_exhibition_id
FROM
ee_photo_{$lazylang} USE INDEX (ee_photo_id),
ee_photo USE INDEX (ee_photo_id),
ee_photo_to_exhibition,
ee_exhibition
WHERE
ee_photo.ee_photo_for_www = 'yes'
AND ee_photo_to_exhibition.ee_photo_id = ee_photo.ee_photo_id
AND ee_photo_to_exhibition.ee_exhibition_id = ee_exhibition.ee_exhibition_id
AND ee_exhibition.ee_exhibition_pass = '{$pass}'
AND ee_photo.ee_photo_id = ee_photo_{$lazylang}.ee_photo_id
{$exhib_where}
GROUP BY ee_photo.ee_photo_id
ORDER BY
ee_photo.ee_photo_id DESC
LIMIT {$amount}
";
$latestpics = mysql_query($latest_sql);
//print nl2br($latest_sql);
if (!$latestpics) {
print mysql_error();
}
}
if ($get == "random_photos") {
$random_sql = "
SELECT
ee_photo.ee_photo_id,
ee_photo_{$lazylang}.ee_photo_header,
ee_photo.ee_photo_exif_datetime,
ee_exhibition.ee_exhibition_id
FROM
ee_photo_{$lazylang} USE INDEX (ee_photo_id),
ee_photo USE INDEX (ee_photo_id),
ee_photo_to_exhibition,
{$catfrom}
ee_exhibition
WHERE
ee_photo.ee_photo_for_www = 'yes'
AND ee_photo_to_exhibition.ee_photo_id = ee_photo.ee_photo_id
AND ee_photo_to_exhibition.ee_exhibition_id = ee_exhibition.ee_exhibition_id
AND ee_exhibition.ee_exhibition_pass = '{$pass}'
AND ee_photo.ee_photo_id = ee_photo_{$lazylang}.ee_photo_id
{$catwhere}
{$orlist}
{$betweenors}
{$exlorlist}
{$catwhere_end}
{$exhib_where}
GROUP BY ee_photo.ee_photo_id
ORDER BY RAND()
LIMIT {$amount}
";
$random = mysql_query($random_sql);
//print "<small>" . nl2br($random_sql) . "</small>";
if (!$random) {
print mysql_error();
}
}
ob_start();
if ($get == "latest_galleries") {
while ($data = mysql_fetch_array($exhibs)) {
print "<a href=\"{$s_ee_html_root}list.php?exhibition=" . $data["ee_exhibition_id"] . "&pass={$pass}&lang={$lang}\">";
print ee_stripslashes($data["ee_exhibition_name"]);
print "</a><br>\n";
}
}
$latest_exhibitions = ob_get_contents();
ob_end_clean();
ob_start();
// bugfix - need to clear old data from $latestarray
$latestarray = array();
if ($get == "latest_photos") {
while ($row = mysql_fetch_array($latestpics)) {
$header = ee_stripslashes($row["ee_photo_header"]);
$exhib = $row["ee_exhibition_id"];
$id = $row["ee_photo_id"];
$latestarray[] = array("exhibition" => $exhib, "photo" => $id);
//print $header . " " . $exhib . " " . $id;
if ($viewas == "text") {
print "<a href=\"{$s_ee_html_root}photo.php?photo={$id}&exhibition={$exhib}&pass={$pass}&lang={$lang}\" target=\"_blank\">{$header}</a><br>\n";
}
}
//ee_print_array($latestarray);
if ($viewas == "image") {
ee_print_thumbs ($latestarray,$thumbsize,$border,$bordercolor,$hsp ace,$vspace);
}
}
$latest_pics = ob_get_contents();
ob_end_clean();
ob_start();
$randarray = array();
if ($get == "random_photos") {
while ($row = mysql_fetch_array($random)) {
$header = ee_stripslashes($row["ee_photo_header"]);
$exhib = $row["ee_exhibition_id"];
$id = $row["ee_photo_id"];
$randarray[] = array("exhibition" => $exhib, "photo" => $id);
if ($viewas == "text") {
print "<a href=\"{$s_ee_html_root}photo.php?photo={$id}&exhibition={$exhib}&pass={$pass}&lang={$lang}\" target=\"_blank\">{$header}</a><br>\n";
}
}
if ($viewas == "image") {
ee_print_thumbs ($randarray,$thumbsize,$border,$bordercolor,$hspac e,$vspace);
}
}
$random_pics = ob_get_contents();
ob_end_clean();
if ($get == "latest_galleries") {
print $latest_exhibitions;
}
if ($get == "latest_photos") {
print $latest_pics;
}
if ($get == "random_photos") {
print $random_pics;
}
mysql_close();
?>
ee_snip_func.php<?php
// ee snippets functions v1.5RC4
// not a bugfix - removed default values in the definition line
function ee_print_thumbs ($array,$type,$border,$bordercolor,$hspace,$vspace ) {
global $pass;
global $link;
global $s_outputlink_color;
global $s_outputmicrothumb_border;
global $s_outputmicrothumb_border_color;
global $s_imagecheckifthere;
global $size;
global $url;
global $goodlink;
global $errorlink;
global $countretries;
global $retriesleft;
global $translated;
global $lang;
global $lazylang;
global $default_language;
global $s_num_ratings;
global $s_show_ratings;
global $s_ee_html_root;
if ($type != "thumb" && $type != "microthumb") $type = "microthumb";
//ee_print_array($array);
foreach ($array as $key => $data) {
$exhibition = $data["exhibition"];
$id = $data["photo"];
$getthumbs_sql =
"
SELECT
ee_photo.ee_photo_id,
ee_photo.ee_photo_filename,
ee_photo_{$lazylang}.ee_photo_header,
ee_{$type}_path.ee_{$type}_path_url
FROM
ee_photo_{$lazylang},
ee_photo USE INDEX (ee_photo_id),
ee_photo_to_exhibition USE INDEX (ee_photo_id),
ee_exhibition,
ee_{$type}_path,
ee_thumbs
WHERE
ee_photo.ee_photo_for_www = 'yes'
AND ee_photo.ee_photo_id = '$id'
AND ee_photo_to_exhibition.ee_exhibition_id = '$exhibition'
AND ee_photo_to_exhibition.ee_photo_id = ee_photo.ee_photo_id
AND ee_photo_to_exhibition.ee_exhibition_id = ee_exhibition.ee_exhibition_id
AND ee_exhibition.ee_thumbs_id = ee_thumbs.ee_thumbs_id
AND ee_thumbs.ee_{$type}_path_id = ee_{$type}_path.ee_{$type}_path_id
AND ee_exhibition.ee_exhibition_id = '$exhibition'
AND ee_exhibition.ee_exhibition_pass = '$pass'
AND ee_photo_{$lazylang}.ee_photo_id = ee_photo.ee_photo_id
GROUP BY ee_photo.ee_photo_id
";
//print nl2br($getthumbs_sql);
$getthumbs = mysql_query($getthumbs_sql);
if (!$getthumbs) {
}
while ($row = mysql_fetch_array($getthumbs)) {
if (!isset($link)) $link = "";
$urli = $id . $link;
$pathname = ee_stripslashes($row["ee_{$type}_path_url"]);
$filename = ee_stripslashes($row["ee_photo_filename"]);
ee_fixedpath ($pathname,$filename);
$thumbheader = ee_html_conversion(ee_stripslashes($row["ee_photo_header"]));
//bugfix style section after border-color to contain and terminate style statement properly
$goodlink = "<img src=\"" . $url . "\" border=\"" . $border . "\" style=\"border-color:#" . $bordercolor . ";\" hspace=\"{$hspace}\" vspace=\"{$vspace}\" alt=\"{$thumbheader}\">";
print "<a href=\"{$s_ee_html_root}photo.php?photo=";
print $urli;
print "&exhibition=" . $exhibition;
print "&pass=" . $pass;
print "&lang={$lang}";
//bugfix style section after border-color to contain and terminate style statement properly
print "\" style=\"color:#" . $bordercolor . ";\" TITLE=\"" . $thumbheader . "\">";
print $goodlink;
print "</a>\n";
}
}
}
?>
snippetsdemo2.php<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Snippet preview demo</title>
</head>
<body>
<p>
<?php
ini_set("allow_url_fopen",TRUE);
ini_set("display_errors",TRUE);
?>
<?php
$get="latest_galleries";
include("snippets.php");
?>
<p><hr>
<?php
$get="latest_photos";
$viewas="text";
include("snippets.php");
?>
<p><hr>
<?php
$get="random_photos";
$amount="9";
$exhibition="all";
$border="4";
$hspace="10";
$vspace="1";
$bordercolor="000000";
$viewas="image";
include("snippets.php");
?>
<p><hr>
<?php
$get="random_photos";
$amount="5";
$border="1";
$bordercolor="0000ff";
$viewas="image";
$thumbsize="microthumb";
$includecategory="1";
include("snippets.php");
?>
<p><hr>
<?php
$get="random_photos";
$amount="5";
$border="1";
$bordercolor="cccccc";
$viewas="image";
$thumbsize="microthumb";
include("snippets.php");
?>
<p>
</body>
</html>
enjoy! if there are any problems, please let me know and i'll take a look and see if i can fix them...
[edit: minor fix to get fetchsettings to set some variables properly. now works correctly with above posted snippetsdemo2.php and original snippetsdemo.php ]
[edit: i dunno what it was, maybe the conversion from phpBB to this package, but for some reason, the <'s and &'s in the code blocks were translated to their < and & counterparts when they shouldn't have been... no matter, took about ten minutes to fix them up and everything /should/ now be able to be copied and pasted like it was before the software change ]
Pekka
12th of August 2004 (Thu), 17:23
Great work Wkitty! :) :) :)
I did not have time now check those changes (it's 2 am here), looks ok, but this one
// bugfix - function parameters... can't pass values in the definition line
is not a bug. It is perfectly ok to place default values to function parameters in function definition.
wkitty42
12th of August 2004 (Thu), 17:38
Great work Wkitty! :) :) :)
I did not have time now check those changes (it's 2 am here), looks ok, but this one
// bugfix - function parameters... can't pass values in the definition line
is not a bug. It is perfectly ok to place default values to function parameters in function definition.
oh! ok... that's fine, then :) i wasn't aware that it could be done and i wasn't seeing the results i expected until i adjusted them... i'll correct that in the posting but will leave that function line as is...
2AM? are you pulling one of my stunts where you work several 72hour days and then sleep for a 24hour period ;) ;) ;)
wkitty42
26th of August 2004 (Thu), 19:33
ok, figured it out... now to figure out why it is doing what it is doing... here's the situation...
my server uses .htaccess to block access to the site if the referer and the useragent are both blank.
my system doesn't seem to like php include() being addressed directly to the local filesystem.
putting the snippets.php file in the defined php include directory doesn't work as it should.
php doesn't seem to set a referer or a useragent when doing an include() via http methods.
the combination of the above 4 situations prevented the snippets from working... i ended up adding the setting to display error messages and was finally able to see my 403.1 errorcode which i setup for the no useragent no referer situation... that lead me to my .htaccess file to try to find a workaround... the /only/ workaround i was able to find was to specify my server's ip address in the exclusion list...
while researching another situation with PHP, i came across the user_agent ini setting... this is apparently also able to be set in .htaccess so that you may have different user agents depending on the directory...
i've added the following to the original snippetsdemo.php and the snippets demo does work and specify the useragent as needed by my system...
find this<?php
ini_set("allow_url_fopen",TRUE);
?>
and change it to<?php
ini_set("allow_url_fopen",TRUE);
ini_set("user_agent","ExhibitEngine SnippetDemo");
?>
put what you like in the user_agent setting... your logs will show your own system accessing your server via http with the above useragent... its kinda wierd seeing your own server accessing itself in this manner... one may want to adjust one's webserver log analysis software for this, too...
here's a sample logfile entry where the server is accessing itself...www.xxx.yyy.zzz - - [26/Aug/2004:21:33:27 -0400] "GET /EEngine/snippets.php?get=random_photos&amount=5&border=1&bordercolor=0000ff&viewas=image&thumbsize=microthumb&includecategory=1 HTTP/1.0" 200 1743 "-" "ExhibitEngine SnippetDemo"
[edit: added example log entry]
[edit: pesky conversion routines goofed on every < and & character in my posts... hopefully i got them all... now to hunt down any others and correct them :evil:]
vBulletin® v3.6.12, Copyright ©2000-2012, Jelsoft Enterprises Ltd.