home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2006 April / PCnet 2006-06.4.iso / shareware / nmsetup.exe / WebServer / web / slideshow.php < prev    next >
Encoding:
PHP Script  |  2006-05-01  |  13.7 KB  |  340 lines

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // <!--Copyright (c) 2005 Pure Networks Inc.  All rights reserved.-->
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Build: 3.0.6121.0 (Stable)
  7. // $Revision: #2 $
  8. //
  9.  
  10. $sNavLocation       =   "slideshow";
  11. require "_session_common.php";
  12. ///////////////////////////////////////////////////
  13. // Make sure that we have a valid share passed in.
  14. ///////////////////////////////////////////////////
  15. if (!isset($_GET['share']) or $_GET['share'] == "")
  16. {
  17.     log_activity("QS check", "failure", return_error_text(200, "", $arErrors));
  18.     gotoAbs('/error/200/return');
  19.     exit();
  20. }
  21. else
  22. {
  23.     $sShare = $_GET['share'];
  24.     log_activity("slideshow share", "info", $sShare);
  25. }
  26. ///////////////////////////////////////////////////
  27. // Make sure that we have a valid path passed in.
  28. ///////////////////////////////////////////////////
  29. if (!isset($_GET['path']) or $_GET['path'] == "")
  30. {
  31.     log_activity("QS check", "failure", return_error_text(201, "", $arErrors));
  32.     gotoAbs('/error/201/return');
  33.     exit();
  34. }
  35. else
  36. {
  37.     $sPath = urlDecodeString($_GET['path']);
  38.     log_activity("slideshow path", "info", $sPath);
  39. }
  40. require '_folderutils.php';
  41. ///////////////////////////////////////////////////
  42. // Are we starting a new slideshow or contiuing one?
  43. ///////////////////////////////////////////////////
  44. $bStart = false;
  45. if ($_GET['start'] == "true")
  46. {
  47.     $bStart = true;
  48.     log_activity("slideshow started", "info", "");
  49. }
  50. ///////////////////////////////////////////////////
  51. // Get information on the share
  52. ///////////////////////////////////////////////////
  53. try //TODO what is not needed here?
  54. {
  55.     $nmSharedPlace = $nmNetworkLib->OpenShare($sShare);
  56.     $sNetworkName = $nmNetworkLib->NetworkName;
  57.     $sContainer = $nmSharedPlace->DisplayName;
  58.     $sUnc = $nmSharedPlace->Unc;
  59.     $sFolderPath = $sPath;
  60.     $sFolderShortPath = basename($sFolderPath);
  61. }
  62. catch(Exception $ex)
  63. {
  64.     log_activity("slideshow", "exception", $ex->getMessage());
  65.     gotoAbs('/error/103');
  66.     exit();
  67. }
  68. ///////////////////////////////////////////////////
  69. // This check only works for a real folder path, not the root UNC path
  70. ///////////////////////////////////////////////////
  71. if ((strcmp($sFolderPath, $sUnc) != 0) && !file_exists($sFolderPath))
  72. {
  73.     // The path does not match up to the share path
  74.     log_activity("slideshow", "error", return_error_text(301, "", $arErrors));
  75.     gotoAbs('/error/301');
  76.     exit();
  77. }
  78. ///////////////////////////////////////////////////
  79. // The user is not logged in, if this is a private share, send them away.
  80. ///////////////////////////////////////////////////
  81. if (!$bLoggedIn)
  82. {
  83.     try
  84.     {
  85.         $sAccessLevel = $nmSharedPlace->AccessLevel;
  86.     }
  87.     catch(Exception $ex)
  88.     {
  89.         log_activity("Attempting nmSharedPlace->AccessLevel", "exception", $ex->getMessage());
  90.         gotoAbs('/error/305/return');
  91.         exit();
  92.     }
  93.     
  94.     if ($sAccessLevel != 0)
  95.     {
  96.         log_activity("private folder request without session", "error", return_error_text(308, "", $arErrors));
  97.         gotoAbs('/login/308');
  98.         exit();
  99.     }
  100. }
  101. ///////////////////////////////////////////////////
  102. // Do we have a file array in session, or should we make one?
  103. ///////////////////////////////////////////////////
  104. $cFiles = 0;
  105. if ($bStart)
  106. {
  107.     if (isset($_SESSION['SlideshowFileArray']))
  108.     {
  109.         // we're on start, let's wipe any previous slideshow from session and create a new array
  110.         $_SESSION['SlideshowFileArray'] = "";
  111.         $_SESSION['SlideshowHelperArray'] = "";
  112.     }
  113.     createFileArray($sShare, $sFolderPath, $nmSharedPlace);
  114. }
  115. else
  116. {
  117.     if (!isset($_SESSION['SlideshowFileArray']))
  118.     {
  119.         // we're not on start and we don't have a session filearray, we must have been bookmarked
  120.         // let's re-create teh filearray and set the picture to zero
  121.         createFileArray($sShare, $sFolderPath, $nmSharedPlace);
  122.         $iImageNumber = 0;
  123.     }
  124.     else
  125.     {
  126.         // we're not on start and have an array in session, let's compare it to the passed path and
  127.         // make sure it's the correct one to use, if not, blow it away and create one.
  128.         $filesArrayHelper = $_SESSION['SlideshowHelperArray'];
  129.         if ($sShare != $filesArrayHelper[0] OR $sFolderPath != $filesArrayHelper[1])
  130.         {
  131.             $_SESSION['SlideshowFileArray'] = "";
  132.             $_SESSION['SlideshowHelperArray'] = "";
  133.             createFileArray($sShare, $sFolderPath, $nmSharedPlace);
  134.         }
  135.     }
  136. }
  137. $filesArray = $_SESSION['SlideshowFileArray'];
  138. $iFileArraySize = count($filesArray);
  139.  
  140. ///////////////////////////////////////////////////
  141. // What is our image number?  Let's validate it.
  142. ///////////////////////////////////////////////////
  143. $iImageNumber = intval($_GET['image']);
  144. if ($iImageNumber >= $iFileArraySize)
  145. {
  146.     // if we hit the end of the array, let's start over at the beginning
  147.     $iImageNumber = 0;
  148. }
  149. if ($iImageNumber < 0)
  150. {
  151.     // if we're on the first picture and someone hit previous, let's go to the end
  152.     $iImageNumber = ($iFileArraySize - 1);
  153. }
  154. ?>
  155. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  156. <html>
  157. <head>
  158. <?php
  159.     require "_cookie_util.php";
  160. ?>
  161. <script type="text/javascript" language="JavaScript">
  162.         writeCookie();
  163. </script>
  164. <?php
  165.     $screen_res = $_COOKIE['users_res'];
  166.     $screen_res_tmp = explode("x", $screen_res);
  167.     $screen_width = $screen_res_tmp[0];
  168.     $screen_height = $screen_res_tmp[1]; 
  169.  
  170.     if ($iFileArraySize > 0)
  171.     {
  172. ?>
  173.         <meta http-equiv="refresh" content="<?php echo($iRefreshInterval);?>;url=/slideshow/<?php echo($sShare);?>/<?php echo(urlEncodeString($sFolderPath));?>/?image=<?php echo($iImageNumber+1);?>&start=false&refresh=<?php echo($iRefreshSeconds);?>">
  174. <?php
  175.     }
  176. ?>
  177. <title><?php echo htmlspecialchars(returnPageTitle($sIntroHeadline, $sProductNameInformal, $nmSharedPlace, $sPath, $fileName)); ?></title>
  178. <?php     require "_styles_import.php"; ?>
  179. <script type="text/javascript">
  180.     function show_controls_max()
  181.     {
  182.         document.getElementById('SlideshowMaxContain').style.visibility = 'visible';
  183.         document.getElementById('SlideshowMaxContain').style.display = 'inline';
  184.         
  185.         document.getElementById('SlideshowMinContain').style.visibility = 'hidden';
  186.         document.getElementById('SlideshowMinContain').style.display = 'none';
  187.     }
  188.     
  189.     function show_controls_min()
  190.     {
  191.         document.getElementById('SlideshowMaxContain').style.visibility = 'hidden';
  192.         document.getElementById('SlideshowMaxContain').style.display = 'none';
  193.         
  194.         document.getElementById('SlideshowMinContain').style.visibility = 'visible';
  195.         document.getElementById('SlideshowMinContain').style.display = 'inline';
  196.     }
  197. </script>
  198. </head>
  199. <body class="Slideshow" onLoad="writeCookie();">
  200. <!--Copyright (c) 2005 Pure Networks Inc.  All rights reserved.-->
  201. <?php 
  202. if ($iFileArraySize > 0)
  203. {
  204.     $sFullFilePath = $sFolderPath . "\\" . $filesArray[$iImageNumber];
  205.     
  206.     ///////////////////////////////////////////////////
  207.     // get the path to the midsize image
  208.     ///////////////////////////////////////////////////
  209.     try
  210.     {
  211.         $imgLocation = $nmRaManager->GetThumbnailForFile($sFullFilePath, $iSlideshowWidth, 
  212.                                                          $iSlideshowHeight, $sContentBackground);
  213.         // let's get the thumbnail's size whiel we have the UNC path to the thumbnail
  214.         $arImageInfo = getimagesize($imgLocation);
  215.         $image_width = $arImageInfo[0];
  216.         $image_height = $arImageInfo[1];
  217.         $iImageType = $arImageInfo[2];
  218.         // GetThumbnailForFile returns an absolute path; turn it into a relative path for 
  219.         // HTML consumption.
  220.         $imgLocation = substr($imgLocation, strlen($nmRaManager->AppDataDir));
  221.         $imgLocation = urlEncodeString(str_replace("\\", "/", $imgLocation));
  222.     }
  223.     catch(com_exception $ex)
  224.     {
  225.         // An error occurred while attempting to get the image, display bad image pic
  226.         $imgLocation    = "styles/default/image.broken.gif";
  227.         $imgMode        = "Bad";
  228.         log_activity("get thumbnail for " . $sFullFilePath, "exception", $ex->getMessage());
  229.     }
  230.     ///////////////////////////////////////////////////
  231.     // do we need to resize the image? Let's start w/ that
  232.     ///////////////////////////////////////////////////
  233.     if (isset($arImageInfo))
  234.     {
  235.         $arImageInfo = array();
  236.     }
  237.     $viewlink = $imgLocation;
  238. ?>
  239.     <table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
  240.         <tr>
  241.             <td>
  242.                 <div class="SlideshowImage"><img src="<?php echo ($viewlink); ?>" width="<?php echo($image_width);?>" height="<?php echo($image_height);?>" alt="<?php echo(substr(strrchr($sFullFilePath,"\\"),1)); ?>" /></div>
  243.             </td>
  244.         </tr>
  245.         <tr>
  246.             <td>
  247.                 <div id="SlideshowMaxContain" name="SlideshowMaxContain" class="SlideshowMaxContain">
  248.                     <table cellpadding="0" cellspacing="0" border="0" width="100%">
  249.                         <tr>
  250.                             <td class="SlideshowLeft"><div> </div></td>
  251.                             <td align="right" class="SlideshowMid">
  252.                                 <div class="SlideshowButtonContain">
  253.                                     <span class="SlideshowPrev" onmouseover="this.className='SlideshowPrevHover'" onmouseout="this.className='SlideshowPrev'"><a href="/slideshow/<?php echo($sShare);?>/<?php echo(urlEncodeString($sFolderPath));?>/?image=<?php echo($iImageNumber-1);?>&start=false&refresh=<?php echo($iRefreshSeconds);?>" title="Previous slideshow image"><img src="/images/pixel.trans.gif" alt="" border="0"></a></span>
  254.                                     <span class="SlideshowNext" onmouseover="this.className='SlideshowNextHover'" onmouseout="this.className='SlideshowNext'"><a href="/slideshow/<?php echo($sShare);?>/<?php echo(urlEncodeString($sFolderPath));?>/?image=<?php echo($iImageNumber+1);?>&start=false&refresh=<?php echo($iRefreshSeconds);?>" title="Next slideshow image"><img src="/images/pixel.trans.gif" alt="" border="0"></a></span>
  255.                                 </div>
  256.                             </td>
  257.                             <td align="right" class="SlideshowRight"><div> </div></td>
  258.                         </tr>
  259.                     </table>
  260.                 </div>
  261.                 
  262.                 <div id="SlideshowMinContain" name="SlideshowMinContain" style="visibility:hidden;display:none;">
  263.                     <table cellpadding="0" cellspacing="0" border="0" width="100%" >
  264.                         <tr>
  265.                             <td width="45%"><div class="SlideshowMinBg"><img src="/images/pixel.trans.gif" width="1" height="1" alt=""></div></td>
  266.                             <td class="SlideshowGrabber"><a href="javascript:show_controls_max();"><img src="/images/pixel.trans.gif" border="0"alt=""></a></td>
  267.                             <td width="45%"><div class="SlideshowMinBg"><img src="/images/pixel.trans.gif" width="1" height="1" alt=""></div></td>
  268.                         </tr>
  269.                     </table>
  270.                 </div>
  271.                 
  272.             </td>
  273.         </tr>
  274.     </table>
  275. <?php
  276.     ///////////////////////////////////////////////////
  277.     // get the path to the NEXT midsize image to spare cycles
  278.     ///////////////////////////////////////////////////
  279.     $sFullFilePath = $sFolderPath . "\\" . $filesArray[$iImageNumber + 1];
  280.     try
  281.     {
  282.         $imgLocation = $nmRaManager->GetThumbnailForFile($sFullFilePath, $iMidSizeWidth, $iMidSizeHeight, $sContentBackground);
  283.     }
  284.     catch(com_exception $ex)
  285.     {
  286.         log_activity("get thumbnail for " . $sFullFilePath, "exception", $ex->getMessage());
  287.     }
  288. }
  289. else
  290. {
  291.     log_activity("slideshow", "error", return_error_text(xxx, "", $arErrors));
  292.     gotoAbs('/error/401');
  293.     exit();
  294. }
  295. ?>
  296.     </body>
  297. </html>
  298. <?php
  299. ///////////////////////////////////////////////////
  300. // Build up an array of displayable files for session
  301. ///////////////////////////////////////////////////
  302. function createFileArray($sShare, $sFolderPath, $nmSharedPlace)
  303. {
  304.     log_activity("slideshow create", "info", "new session cache");
  305.     $handle = opendir($sFolderPath);
  306.     $filesArray = array();
  307.     while (false !== ($file = readdir($handle)))
  308.     {
  309.         $sFullFilePath = $sFolderPath . "\\" . $file;
  310.         if (!is_dir($sFullFilePath) && ($file != ".") && ($file != ".."))
  311.         {
  312.             $fileExtension = strtolower(strrchr($sFullFilePath, "."));
  313.  
  314.             switch ($fileExtension) 
  315.             {
  316.                 case ".gif":
  317.                 case ".jpg":
  318.                 case ".jpe":
  319.                 case ".jpeg":
  320.                 case ".bmp":
  321.                 case ".png":
  322.                     // add gif, jpg, bmp, and png files to the slideshow array
  323.                     if ($nmSharedPlace->IsDisplayableItem($sFullFilePath) && is_file($sFullFilePath) && is_readable($sFullFilePath))
  324.                     {
  325.                         $filesArray[] = $file;
  326.                     }
  327.                     break;
  328.             }
  329.         }
  330.     }
  331.     // Now that we have the files aray, let's create a helper array with info on 
  332.     // the share and path for the array in teh session
  333.     $filesArrayHelper = "";
  334.     $filesArrayHelper[0] = $sShare;
  335.     $filesArrayHelper[1] = $sFolderPath;
  336.     // now let's store the arrays in the session
  337.     $_SESSION['SlideshowHelperArray'] = $filesArrayHelper;
  338.     $_SESSION['SlideshowFileArray'] = $filesArray;
  339. }
  340. ?>