<?php

 

require_once('config.php');

require_once($config["lib-path"].'xcConfig.class.php');

require_once($config["lib-path"].'xgFactory.class.php');

require_once($config["lib-path"].'xcPaginator.class.php');

 

$root        = xcConfig::get("root-path");

$url        = xcConfig::get("url");

$lang       = xcConfig::get("lang");

 

$folder      = xgFactory::createItem($url);

$parent      = $folder->getParent();

$columnCount = xcConfig::get("gallery-column-count");

$pageinator  = new xcPaginator($folder->getChildren(xcConfig::get("gallery-flat")));

 

//xgFactory::createItem($url);

 

// Head

echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n";

echo "<html>\n";

echo "<head>\n";

echo "      <title>".$folder->getTitle()."</title>\n";

echo "      <link rel=\"alternate\"  href=\"".$root."rss.php?url=".$url."\" type=\"application/rss+xml\" title=\"".$folder->getTitle()."\" id=\"gallery\" />\n";

echo "      <link rel=\"stylesheet\" href=\"gallery.css\" media=\"all\" />\n";

 

echo "      <style type=\"text/css\">\n";

echo "            .mbf-item { display: none; }\n";

echo "      </style>\n";

echo "      <script type='text/javascript' src='../../js/size.js'></script>";

echo "</head>\n";

echo "<body>\n";

 

// Title

echo "      <table id=\"head\" cellspacing='10px'>\n         <tr>\n                  <td colspan='2' id=\"title\">";

if($lang == "english"){

      echo '<img src="logoGalleryEnglish.jpg" />';

}

else{

      echo '<img src="logoGalleryGerman.jpg" />';

}

echo "</td>\n                <td rowspan='2'>";

// Table

 

 

 

 

//preprocessing

 

for($j=0; $j<5; $j++) {

      for($k=0; $k<5; $k++) {

            $allocatedCells[$j][$k]=false;

      }

}

 

$tempPos = array(0,1,2,3,4);

for($i=0; $i<5; $i++){

      $randPos = rand(0,(count($tempPos)-1));

      $imagePosition[$i] = $tempPos[$randPos];

      //echo $randPos."   ".$imagePosition[$i]."<br>";

      //print_r($tempPos);

      unset($tempPos[$randPos]);

      $tempPos = array_values($tempPos);

      $allocatedCells[$i][$imagePosition[$i]] = true;

}

 

 

echo "\n      <table id=\"galleryTable\" cellspacing='3px'>";

// Pictures

$itemNr = 0;

 

foreach ($pageinator->getEntries() as $item) {

      // new row

      echo "\n               <tr>\n";

 

      for($i=0; $i<5; $i++){

 

            // display item

            if($i == $imagePosition[$itemNr]){

                  echo "                        <td>\n";

                  if ($item instanceof xgFolder) {

                        echo "                              <a href=\"".$root."gallery.php?url=".$item->getLink()."\">\n";

                        echo "                              <img src=\"".$root."".$item->getThumbnailUrl()."\" />";

 

 

                  } else {

                        echo "                              <a href=\"".$root."image.php?url=".$item->getLink()."\">\n";

                        echo "                              <img src=\"".$root."image.php?url=".$item->getThumbnailUrl()."\" />";

 

                  }

                  echo "<span class=\"mbf-item\">#gallery ".$item->getGUID()."</span>";

                  echo "</a>\n";

                  echo "                        </td>\n";

            }

            // empty cells

            else{

                  if($allocatedCells[$itemNr][$i] == false){

 

                        $direction = rand(0,1);

                        if($direction == 0)

                        {

                              //horizontal

                              $col = $i;

                              $max = 0;

                              while($col<(5-$i) && $allocatedCells[$itemNr][$col] == false)

                              {

                                    $max++;

                                    $col++;

                              }

                              $howFar = rand(1,$max);

                              echo "                        <td colspan='".$howFar."' class='horizontal'>\n";

                              for($n=0; $n<$howFar; $n++){

                                    $allocatedCells[$itemNr][$i+$n] = true;

                              }

                        }

                        //vertical

                        else{

                              $row = $itemNr;

                              $max = 0;

                              while($row<(5-$itemNr) && $allocatedCells[$row][$i] == false)

                              {

                                    $max++;

                                    $row++;

                              }

                              $howFar = rand(1,$max);

                              echo "                        <td rowspan='".$howFar."' class='vertical'>\n";

                              for($n=0; $n<$howFar; $n++){

                                    $allocatedCells[$itemNr+$n][$i] = true;

                              }

                        }

                        echo "                        &nbsp;</td>\n";

                  }

            }

           

      }

      echo "                  </tr>\n";

 

      $itemNr++;

}

 

//extra links

      echo "      </table>\n              </td>\n                       </tr>\n           <tr>\n                  <td id=\"grass\">";

      echo "<div id=\"sourceCodelinks\">";

      if($lang == "english"){           

            echo "                              <a href=\"sourceCodeGallery.html\" target=\"_blank\">Source Code</a><br />\n";

            echo "                              <a href=\"configGallery.html\" target=\"_blank\">Config File</a>\n";

      }

      else {

            echo "                              <a href=\"sourceCodeGallery.html\" target=\"_blank\">Quelltext</a><br />\n";

            echo "                              <a href=\"configGallery.html\" target=\"_blank\">Konfigurationsdatei</a>\n";

      }

      echo "                              <a href=\"http://r3novatio.deviantart.com\" target=\"_blank\">Deviantart</a>\n";

      echo "                        </div>";

      echo "</td>\n                <td id=\"green\">";

 

// Pagination Links

if ($pageinator->needPageination()) {

      $pageLinks = "gallery.php?url=".$folder->getLink()."&";

      if($lang == "english"){

                  $pageLinks = $pageLinks.'lang=';

                  $pageLinks = $pageLinks.$lang;

                  $pageLinks = $pageLinks.'&';

            }

      echo $pageinator->getPageLinks($pageLinks, "", "<br />", "<span id='currentPage'>", "</span>")."</div>";

}

 

echo "</td>\n          </tr>\n      </table>\n";

 

// Error div

if (xcConfig::hasErrors()) {

 

      echo "      <div id=\"errors\">\n";

      echo "<b>ERROR LOG</b>";

      echo "<hr size=\"1\" style=\"color:#ccc\" />\n";

      foreach (xcConfig::getErrors() as $error) {

            echo $error."<br />";

      }

      echo "      </div>\n";

}

 

echo "\n</body>\n";

echo "</html>";

 

?>