Advertisement
terorama

showpics.php

Aug 21st, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. define('GRABBED',
  5.    'http://kimdm79.hostenko.com/examples/phpnew/parsed_2507287279.txt');
  6.    
  7. define('FAVS','../favpics.txt');
  8.    
  9.    //set_time_limit(0);
  10.    //ob_implicit_flush();
  11.    
  12.    /*$zstr=file_get_contents(GRABBED);
  13.    header('Content-type:text/plain');
  14.    echo $zstr;
  15.    exit();*/
  16.    
  17.    if (!isset($_POST['step'])) {
  18.       session_start();
  19.       session_destroy();
  20.       session_commit();
  21.      
  22.       zpage();
  23.       exit();
  24.    }
  25.    //------------------------------------
  26.    session_start();
  27.    //--------------------------post fav
  28.    if (isset($_POST['favpic'])) {
  29.    
  30.       if (!file_exists(FAVS)) {
  31.          $fhandle=fopen(FAVS,'wb');
  32.          fclose($fhandle);
  33.       }
  34.      
  35.       $fhandle=fopen(FAVS,'ab');
  36.       fwrite($fhandle,$_POST['favpic']."\r\n");
  37.       fclose($fhandle);
  38.       echo 'ok';
  39.       exit();
  40.      
  41.    }
  42.    //------------------------------------
  43.    if (isset($_SESSION['zstru']))
  44.       $zstru=$_SESSION['zstru'];
  45.    else
  46.       $zstru=file_get_contents(GRABBED);
  47.    
  48.    
  49.    $f=strpos($zstru,"\r\n");
  50.    $nims=0;
  51.    
  52.    $items_out=array();
  53.    
  54.    while (($f!=-1) && ($nims<32)) {
  55.    
  56.       $item_out=array();
  57.       $zelem=substr($zstru,0,$f);
  58.  
  59.      
  60.       $zstru=substr($zstru,$f+2);
  61.      
  62.       $zarr=explode('|ABC|',$zelem);
  63.       $im=array_pop($zarr);
  64.       $rel=array_pop($zarr);
  65.      
  66.       if ($rel!='') {
  67.          $im=str_replace('..','http://kimdm79.hostenko.com/examples/phpnew',$im);
  68.          //echo '<img src="'.$im.'" rel="'.$rel.'" />';
  69.          
  70.          $item_out['small']=$im;
  71.          $item_out['big']=$rel;
  72.          
  73.          $items_out[]=$item_out;
  74.          $nims++;
  75.          }
  76.      
  77.       $f=strpos($zstru,"\r\n");
  78.  
  79.    }
  80.    $_SESSION['zstru']=$zstru;
  81.    session_commit();
  82.    
  83.    echo json_encode($items_out);
  84.    
  85. //---------------------------------------------
  86. function zpage() {
  87.  
  88. ?>
  89.  
  90. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  91. <html xmlns="http://www.w3.org/1999/xhtml">
  92.  
  93. <head>
  94.    <script type='text/javascript' src='js/jquery-1.7.2.js'></script>
  95.    
  96.    <script type="text/javascript">
  97.    
  98.       var gl_scroll=0;
  99.       var scrTop=0;
  100.       var prevX, prevY;
  101.       var gl_moved;
  102.      
  103.       //--------------------------------------toggle lightbox
  104.       function showlb(on) {
  105.          if (on) {
  106.             $('#lbox').css('width',screen.width+'px');
  107.             $('#lbox').css('height',screen.height+'px');
  108.            
  109.             $('#lbox').fadeIn('slow');
  110.          }
  111.          else {
  112.             $('#lbox').fadeOut('slow');
  113.          }
  114.          
  115.       }
  116.      
  117.       //--------------------------------scroll event handler
  118.       function scrollEv() {
  119.      
  120.          scrolled = window.pageYOffset || document.documentElement.scrollTop;
  121.          
  122.          if (scrolled<scrTop) {
  123.             scrTop=scrolled;
  124.             return;
  125.             }          
  126.          scrTop=scrolled;  
  127.          
  128.          if (gl_scroll!=0) {
  129.             return;
  130.          }
  131.          
  132.          
  133.          
  134.          load_pics();
  135.       }
  136.        
  137.       //------------------------------load pictures
  138.       function load_pics() {
  139.        
  140.          var pageHeight = document.documentElement.clientHeight;
  141.          var scrolled = window.pageYOffset || document.documentElement.scrollTop;
  142.          
  143.          var contentHeight = $('#allpics').height()+$('#allpics').position().top;
  144.          
  145.          if ((pageHeight+scrolled)>(contentHeight-1000)) {
  146.             //alert('go');
  147.             if  ($('#allpics .img_div').length>200) {
  148.                $('#allpics .img_div').slice(0,32).remove();
  149.             }
  150.          
  151.             gl_scroll=1;
  152.             //----------------------------------------------------------------
  153.             $.ajax ( {
  154.                type: 'POST',
  155.                url:  '<?=$_SERVER['PHP_SELF']?>',
  156.                dataType: 'json',
  157.                data: {step:''}
  158.             }
  159.             //-----------------------------------
  160.             ).done(
  161.                function(infj) {
  162.                   //--------------------------------
  163.                   $.each(infj, function(i,valu) {
  164.                      var zDiv=$('<div>',{'class':'img_div'});
  165.                      var zImg=$('<img>',{'src':valu['small'],'rel':valu['big']});
  166.                      //--------------------------------
  167.                      /*zImg.load(function() {
  168.                         var imgf= new Image();
  169.                         imgf.src=$(this).attr('rel');
  170.                      });*/
  171.                      //--------------------------------
  172.                      
  173.                      zImg.click(function() {                                 
  174.                         var imgz= new Image();
  175.                         imgz.src=$(this).attr('rel');
  176.                        
  177.                         save_result(
  178.                            $(this).attr('rel')+'|ABC|'+
  179.                            $(this).attr('src'));
  180.                  
  181.                         $(imgz).load (function() { 
  182.                        
  183.                            $('#inpic img').attr('src',this.src);                           
  184.                            $('#inpic').css('left',
  185.                            Math.floor(screen.width/2-this.width/2)+'px');              
  186.                            $('#inpic').css('top',
  187.                            Math.floor(screen.height/2-this.height/2)+'px');                                            
  188.                            showlb(true);
  189.                         });
  190.                         }
  191.                      )
  192.                      //--------------------------------
  193.                      zDiv.append(zImg);
  194.                      $('#allpics').find('#zclose').before(zDiv);
  195.                      
  196.                   });
  197.                  
  198.                   gl_scroll=0;
  199.             });
  200.  
  201.          }
  202.       }
  203.      
  204.       //----------------------------------------------------------
  205.       function save_result(inpic) {
  206.         $.ajax ( {
  207.                type: 'POST',
  208.                url:  '<?=$_SERVER['PHP_SELF']?>',
  209.                data: {step:'', favpic:inpic}
  210.             }).done(
  211.                function(html) {
  212.                   //alert(html);
  213.                });
  214.      
  215.       }
  216.      
  217.       //----------------------------------------------------------
  218.       function mouseDown(e) {
  219.      
  220.          e= e || event;
  221.          
  222.          prevX=e.clientX;
  223.          prevY=e.clientY;
  224.          
  225.          $('#inpic').bind('mousemove',mouseMove);
  226.          $('#inpic').bind('mouseup',mouseUp);
  227.          
  228.          gl_moved=false;
  229.          
  230.          return false;
  231.       }
  232.       //----------------------------------
  233.       function mouseMove(e) {
  234.          
  235.          e = e || event;
  236.          var diffX = e.clientX-prevX;
  237.          var diffY = e.clientY-prevY;
  238.          
  239.          prevX=e.clientX;
  240.          prevY=e.clientY;
  241.          
  242.          $(this).css('left', (this.offsetLeft+diffX)+'px');
  243.          $(this).css('top', (this.offsetTop+diffY)+'px');
  244.          
  245.          gl_moved=true;
  246.       }
  247.       //----------------------------------
  248.       function mouseUp(e) {
  249.          $(this).unbind('mouseup',mouseUp);
  250.          $(this).unbind('mousemove',mouseMove);
  251.          
  252.          if (!gl_moved) {
  253.             showlb(false);
  254.          }
  255.          
  256.          //e = e || event;
  257.          //e.stopPropagation();
  258.          
  259.       }
  260.       //----------------------------------------------------------
  261.       $(document).ready(
  262.          function() {
  263.              
  264.             //-----------------------------------------------------
  265.             $(window).scroll(scrollEv);
  266.             $(window).on('resize',scrollEv);
  267.                
  268.             //-----------------------------------------------------
  269.  
  270.             $('#lbox').click( function() {
  271.                showlb(false);
  272.             });
  273.             //------------------------
  274.             $('#inpic').click( function(event) {
  275.            
  276.                event = event || window.event;
  277.                if (event.stopPropagation) {
  278.                   event.stopPropagation();
  279.                } else {
  280.                   event.cancelBubble=true;
  281.                };
  282.                
  283.            
  284.             })
  285.             $('#inpic').bind('mousedown',mouseDown);
  286.            
  287.             //-----------------------------
  288.             scrollEv();
  289.             //setTimeout(scrollEv,2000);
  290.             //setTimeout(scrollEv,4000);
  291.            
  292.            
  293.          }
  294.       )
  295.    </script>
  296. </head>
  297.  
  298. <style type="text/css">
  299.    * {
  300.       margin:0;
  301.       padding:0;
  302.    }
  303.    
  304.    .img_div {
  305.       cursor:pointer;
  306.       width:300px;
  307.       height:200px;
  308.       overflow:hidden;
  309.      
  310.       border-right:dotted 1px black;
  311.       border-bottom:dotted 1px black;
  312.       float:left;
  313.      
  314.    }
  315.    
  316.    #lbox {
  317.       position:fixed;
  318.      
  319.    }
  320.    
  321.    #shade {
  322.       position:absolute;
  323.       background-color:black;
  324.       opacity:0.8;
  325.       filter:alpha(opacity=80);
  326.       width:100%;
  327.       height:100%;
  328.       z-index:100;
  329.    }
  330.    
  331.    #inpic {
  332.       position:absolute;
  333.       z-index:200;
  334.       cursor:pointer;
  335.      
  336.    }
  337.    
  338. </style>
  339.  
  340.  
  341. <body>
  342. <div id="lbox">
  343.   <div id="shade"></div>
  344.   <div id="inpic"><img /></div>
  345. </div>
  346.  
  347. <div id="allpics">
  348.  
  349.  
  350.    <div id="zclose"
  351.       style="height:400px;background:#eee;border:solid 1px  black;clear:both">
  352.      
  353.       <?php
  354.          /*$favs=file(FAVS);
  355.          foreach ($favs as $fav) {
  356.          
  357.             $zarr=explode('|ABC|',$fav);
  358.             $im=array_pop($zarr);
  359.             $rel=array_pop($zarr);
  360.      
  361.             if ($rel!='') {
  362.                $im=str_replace('..','http://kimdm79.hostenko.com/examples/phpnew',$im);
  363.                echo '<img src="'.$im.'" rel="'.$rel.'" />';
  364.             }      
  365.          }*/
  366.      
  367.      
  368.       ?>
  369.    </div>
  370.  
  371.  
  372. </div>
  373. </body></html>
  374.  
  375. <?php
  376. }
  377. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement