PDA

View Full Version : Image gallery


deathson
04-22-2006, 07:36 AM
I created a mod xml driven, that creates a small gallery of pictures at the top of the site.
i have a tourism site and i thought it would be cool to have an section with pictures.

check my site and let me know your opinion.
if you show interest on the mod i will publish the code

the site is searchingpanama dot com

imranbaig
04-22-2006, 09:38 AM
how can you make use of these images to fit into our directories?

deathson
04-22-2006, 02:26 PM
NOTES:
the xml is parsed using the domit php library, which you can download from here http://sourceforge.net/projects/domit-xmlparser
I use domit in my projects because it is very portable and the dom is pretty easy to handle with it.

next i created a folder in the root of my phpld installation folder
in my case i named it "hotspots", you can choose any name u want "top models", "links i will never visit", ect .. u get the idea...
as long as you match the xml paths to the images all should be fine.

in the "hotspots" directory i created 2 subdirectories, one for thumbs and one for the big images, and i placed the xml file in there.
i also installed domit in that folder...
so we have the xml file, and the 2 folders for the images and the domit library folder.


here it is the xml file i use

<hotspots title= "Hot Spot of the Day">
<shortText>El Limbo Hotel in Bocas del Toro</shortText>
<fullText>The hotel has been constructed completely on transparent waters of the Caribbean Sea, with 12 different types from local wood respecting the Antillean tipical architecture. Located right in the center of the island of Bocas del Toro, it offers all comfort to him necessary so that it enjoys excellent vacations in contact the nature. Account with 18 comfortables rooms with private bathroom, television of 20" and 29" with cable, conditioned air, great large windows, balconies with unforgettable view to the sea, bar-deck on the water with space of relax and reading, an ample wharf to take sun or to start off for one of the multiple excursions ( dolphins, visits other islands, beaches, snorkeling etc etc.).</fullText>
<links>
<element title="Breakfast in the Bed" url="http://www.ellimbo.com" alt="breakfast" image_thumb="hotspots/images/thumb/limbo_breakfast_bed.jpg" image_big="hotspots/images/big/limbo_breakfast_bed.jpg"/>
<element title="Lobster and the Caribbean" url="http://www.ellimbo.com" alt="lobster" image_thumb="hotspots/images/thumb/limbo_lobster.jpg" image_big="hotspots/images/big/limbo_lobster.jpg"/>
<element title="Lobster and the Caribbean" url="http://www.ellimbo.com" alt="lobby" image_thumb="hotspots/images/thumb/limbo_lobby.jpg" image_big="hotspots/images/big/limbo_lobby.jpg"/>
<element title="Lobster and the Caribbean" url="http://www.ellimbo.com" alt="beach" image_thumb="hotspots/images/thumb/limbo_beach3.jpg" image_big="hotspots/images/big/limbo_beach3.jpg"/>
<element title="Lobster and the Caribbean" url="http://www.ellimbo.com" alt="mermaid" image_thumb="hotspots/images/thumb/limbo_mermaid.jpg" image_big="hotspots/images/big/limbo_mermaid.jpg"/>
</links>
</hotspots>



IMPORTANT!!!
i included the hotspots.tpl file in the main.tpl file

i put the include here

{* Display categories heading if not on homepage *}
{if $category.ID gt 0 and count($categs) gt 0}<h3>{l}Categories{/l}</h3>{/if}

{include file="hotspots.tpl"}

{* Categories *}


AND here it is the hotspots.tpl source code


///BEGIN FILE
{php}

//ERROR_REPORTING(E_ALL);
error_reporting(0);

require_once('/var/www/path_site/hotspots/domit/xml_domit_include.php');

global $XMLtitle, $XMLshortText, $XMLfullText, $XMLtitle, $XMLquestion ;
global $linksArrayXML, $optionsArrayXML;


$linksArrayXML = loadDOM();

echo "\n<script>\n";
echo "function PopupPic(img) {\n";
echo "var url = \"bigimage.php?img=\" + img;\n";
echo " window.open(url,\"\",\"width=400,height=400,resizable,scrollbars=no,statu s=0\");\n";
echo "}\n";
echo "</script>\n";
echo "<h3>".$XMLtitle."</h3>\n";
echo "<table id=\"hotlinks\" width=\"50%\" border=\"0\" bordercolor=\"#000000\" bgcolor=\"#ffffff\">\n";
$col_counter = 0;
$col_max = 3;
$num_pics = count($linksArrayXML); //picture elements from the xml file
for($k=0;$k<$num_pics;$k++) {

$arrayEntry=$linksArrayXML[$k];
$col_counter = $col_counter + 1;
if($col_counter == 1) echo "<tr>\n";
echo "<td><a href=\"javascript:PopupPic('" . $arrayEntry['image_big']."')\"><img alt=\"". $arrayEntry['alt']. "\" src=\"". $arrayEntry['image_thumb'] . "\" border=\"0\"></a></td>\n";
//TO CONTROL THE COLSPAN IN INCOMPLETE ROWS OF PICS
if($col_counter >= $num_pics){
echo str_repeat('<td></td>', $col_max - $col_counter);
$col_counter = $col_max;
}
//TO ADD THE ROW END
if($col_counter >= $col_max){
$col_counter = 0;
echo "</tr>\n";
}

}
echo "</table>\n";

function loadDOM(){

$dom =& new DOMIT_Document();
$success = $dom->loadXML("hotspots/hotspot.xml");
global $linksArrayXML, $optionsArrayXML, $XMLtitle, $XMLquestion;


if ($success) {
//process XML
$root =& $dom->documentElement;
$XMLtitle = $root->getAttribute("title");


//i added two text elements to the xml file. it can be usefull
//for adding descriptions to your pictures.
$shortTextElement =& $dom->documentElement->childNodes[0];
$XMLshortText= $shortTextElement->getText();
$fullTextElement =& $dom->documentElement->childNodes[1];
$XMLfullText= $fullTextElement->getText();

$linksElement =& $dom->documentElement->childNodes[2];

if ($linksElement->hasChildNodes()) {
//get a reference to the childNodes collection of the document element
$myChildNodes =& $linksElement->childNodes;
$numChildren =& $linksElement->childCount;

//iterate through the collection
for ($i = 0; $i < $numChildren; $i++) {
//get a reference to the i childNode
$currentNode =& $myChildNodes[$i];
$title="";
$url = "";
$alt= "";
$image_thumb = "";
$image_big = "";
$arrayEntry = array();


if ($currentNode->hasAttribute("url")) {
//obtain the value of the discid attribute
$arrayEntry["url"] = $currentNode->getAttribute("url");
}

if ($currentNode->hasAttribute("title")) {
//obtain the value title attribute
$arrayEntry["title"] = $currentNode->getAttribute("title");
}

if ($currentNode->hasAttribute("alt")) {
//obtain the value alt attribute
$arrayEntry["alt"] = $currentNode->getAttribute("alt");

}

if ($currentNode->hasAttribute("image_thumb")) {
//obtain the value image_thumb attribute
$arrayEntry["image_thumb"] = $currentNode->getAttribute("image_thumb");

}

if ($currentNode->hasAttribute("image_big")) {
//obtain the value image_big attribute
$arrayEntry["image_big"] = $currentNode->getAttribute("image_big");

}


$linksArrayXML[] = $arrayEntry;

} //for end
} //root has childnodes

return $linksArrayXML;

}



else {

echo "Error code: " . $dom->getErrorCode();
echo "\n
";
echo "Error string: " . $dom->getErrorString();
return $linksArrayXML;
//empty array
}



}



{/php}
///END OF FILE



and that is it...
i am creating an simple administrador to add and remove elements from the xml... that is the second delivery..

if you have questions about it please post them here or send me an email

minute
04-24-2006, 07:38 PM
I've been wanting to add an image gallery to my site, nice piccies of prestige cars, so this may prove highly useful and am looking forward to second installment.

Though I would probably want to have images off the main page, maybe
a one page per car model.