Advertisement
terorama

fb / test45.php

Nov 5th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 36.31 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. //-----------------------------------------------
  5. //    exception and error handlers
  6. //-----------------------------------------------
  7. function exceptionHandler($e)  {
  8.  
  9.    echo '<div class="remark">Uncaught exception'.$e->getMessage().'</div>';
  10. }
  11. //----------------------
  12. function errorHandler($errno, $errstr, $errfile, $errline) {
  13.  
  14.    switch ($errno) {
  15.      
  16.       case E_ERROR:
  17.          echo '<div class="remark">';
  18.          echo 'Error: '.$errstr.'<br/>File: '.$errfile.'<br/>Line: '.$errline;
  19.          echo '</div>';
  20.          break;
  21.          
  22.       case E_WARNING:
  23.          echo '<div class="remark">';
  24.          echo 'Warning: '.$errstr.'<br/>File: '.$errfile.'<br/>Line: '.$errline;
  25.          echo '</div>';
  26.          break;
  27.          
  28.       case E_NOTICE:
  29.          echo '<div class="remark">';
  30.          echo 'Notice: '.$errstr.'<br/>File: '.$errfile.'<br/>Line: '.$errline;
  31.          echo '</div>';
  32.          break;  
  33.          
  34.       case 2048:
  35.          break;
  36.          
  37.       default:
  38.          echo '<div class="remark">';
  39.          echo   'Errno: '.$errno.'<br/>Error: '.$errstr.
  40.               '<br/>File: '.$errfile.'<br/>Line: '.$errline;
  41.          echo '</div>';
  42.          
  43.    }  
  44.    
  45.    
  46.    return true;
  47.    
  48. }
  49.  
  50. set_exception_handler('exceptionHandler');
  51.  
  52. $default_error_handler = set_error_handler('errorHandler');
  53.  
  54. //-----------------------------------------------
  55. require 'fb.inc.php';
  56.  
  57.  
  58.  
  59. //-----------------------------------------------
  60. //           process request
  61. //-----------------------------------------------
  62. $fb = fbManager::getInstance();
  63.  
  64.    if (!isset($_REQUEST['ajax']))
  65.       draw_form();
  66.      
  67.    else
  68.       {
  69.       //---------------------------
  70.       switch ($_REQUEST['reqtype']) {
  71.          case 'showfqlcurr':
  72.          case 'showfqlall':
  73.          case 'showfqlcurr_list':
  74.          case 'showfqlall_list':
  75.            
  76.             $tname = $_REQUEST['req'];
  77.             $tname = trim(substr($tname, strpos($tname, 'from')+4));
  78.             $tname = 'fql_'.substr($tname,0, strpos($tname,' '));          
  79.             break;
  80.          
  81.          case 'showcurr':
  82.          case 'showall':
  83.          case 'showcurr_list':
  84.          case 'showall_list':
  85.            
  86.             $tname = 'fb_'.array_pop(explode('/',$_REQUEST['req']));           
  87.             break;
  88.            
  89.          case 'showcustom':
  90.          case 'showcustomall':
  91.          case 'showcustom_list':
  92.          case 'showcustomall_list':
  93.          
  94.             $tname = $_REQUEST['req'];
  95.             break; 
  96.        }
  97.        
  98.       //---------------------------
  99.       switch ($_REQUEST['reqtype']) {
  100.      
  101.          case 'showfqlcurr':
  102.          case 'showfqlcurr_list':
  103.          case 'showcurr':
  104.          case 'showcurr_list': 
  105.          case 'showcustom':
  106.          case 'showcustom_list':   
  107.          
  108.             $tcurruser=true;
  109.             break;
  110.  
  111.          case 'showfqlall':
  112.          case 'showfqlall_list':
  113.          case 'showall':
  114.          case 'showall_list':  
  115.          case 'showcustomall':
  116.          case 'showcustomall_list':
  117.  
  118.             $tcurruser=false;        
  119.             break;
  120.       }
  121.      
  122.       //---------------------------
  123.       switch ($_REQUEST['reqtype']) {
  124.      
  125.          case 'showcurr':
  126.          case 'showall':         
  127.          case 'showfqlcurr':         
  128.          case 'showfqlall':
  129.          case 'showcustom':
  130.          case 'showcustomall':
  131.  
  132.             $tprocname='db_drawTab';
  133.             break;
  134.            
  135.          case 'showcurr_list': 
  136.          case 'showall_list':            
  137.          case 'showfqlcurr_list':
  138.          case 'showfqlall_list':
  139.          case 'showcustom_list':   
  140.          case 'showcustomall_list':
  141.          
  142.             $tprocname='db_drawList';
  143.             break;
  144.       }  
  145.        
  146.        
  147.       //---------------------------
  148.       switch ($_REQUEST['reqtype']) {
  149.      
  150.          //-----------------------basic
  151.          case 'apigraph':
  152.             echo json_encode($fb->getNode($_REQUEST['req']));
  153.             break;
  154.            
  155.          case 'fql':
  156.             echo json_encode($fb->get_fql($_REQUEST['req']));
  157.             break;
  158.          //------------------------async requests
  159.          case 'apigrapha':
  160.             echo serialize($fb->getNode($_REQUEST['req']));
  161.             break;
  162.            
  163.          case 'fqla':
  164.             echo serialize($fb->get_fql($_REQUEST['req']));
  165.             break;     
  166.            
  167.          //---------------------------------   
  168.          case 'getfqls':
  169.             echo json_encode(getFqls());
  170.             break;
  171.            
  172.          case 'mktab':
  173.             echo '<pre>'.print_r($fb->createNodeTable($_REQUEST['req'],true),true).'</pre>';
  174.             break;
  175.            
  176.          case 'mkfqltab':
  177.             echo '<pre>'.print_r($fb->createFqlTable($_REQUEST['req'],true),true).'</pre>';
  178.             break;
  179.          
  180.          case 'filltab':
  181.             echo '<pre>'.print_r($fb->fillNodeTable($_REQUEST['req']),true).'</pre>';
  182.             break;
  183.            
  184.          case 'fillfqltab':
  185.             echo '<pre>'.print_r($fb->fillFqlTable($_REQUEST['req']),true).'</pre>';
  186.             break;
  187.            
  188.          //---------------------------------------show info      
  189.          case 'showcurr':
  190.          case 'showall':         
  191.          case 'showfqlcurr':         
  192.          case 'showfqlall':
  193.          case 'showcustom':
  194.          case 'showcustomall':
  195.          case 'showcurr_list': 
  196.          case 'showall_list':            
  197.          case 'showfqlcurr_list':
  198.          case 'showfqlall_list':
  199.          case 'showcustom_list':   
  200.          case 'showcustomall_list':
  201.          
  202.             echo $fb->$tprocname($tname, $tcurruser);
  203.             break;
  204.      
  205.          //-------------------------------------------------
  206.            
  207.          case 'drawwidget':
  208.             echo ($fb->drawWidget($_REQUEST['req']));
  209.             break;
  210.            
  211.          //------------------------------complex
  212.          case 'relatedusers':
  213.                
  214.                  $_SESSION["step"]=1;
  215.                  $_SESSION["errorsz"]=0;
  216.                  
  217.                  header('location: '.$_SERVER['PHP_SELF'].
  218.                          '?ajax&reqtype=relatedusers_go');
  219.                  break;
  220.                  
  221.         //---------------------      
  222.         case 'relatedusers_go':
  223.  
  224.                  $fb->writeRelatedUsers();
  225.                  break;
  226.            
  227.          //----------------------------
  228.          case 'relatedusers4':
  229.            
  230.             echo '<h3>Information successfully collected</h3>'.
  231.                  '<pre>'.print_r($fb->findRelatedUsers(),true).'</pre>';
  232.             break;
  233.            
  234.          //----------------------------
  235.          case 'relatedusers5':
  236.            
  237.             echo '<h3>Result page for related users</h3>';
  238.             echo $fb->drawRelatedUsers();
  239.            
  240.             break;
  241.            
  242.          //----------------------------
  243.          case 'likestofql':
  244.          
  245.             $outinf =$fb->likesBasesToFqlUsers();
  246.             echo '<h3>Operation results</h3>';
  247.             echo '<pre>'.print_r($outinf,true).'</pre>';
  248.             break;
  249.            
  250.          }
  251.       }
  252.      
  253. //-------------------------------------------
  254. //            read fqls file
  255. //-------------------------------------------
  256. function getFqls() {
  257.  
  258.    $s = file_get_contents('fql.txt');
  259.    
  260.    $spl3=str_repeat('=',76);
  261.  
  262.    
  263.    $arr = explode($spl3,$s );
  264.    
  265.    //----------------
  266.    
  267.     function inff ($value) {
  268.    
  269.       $spl4=str_repeat('-',76);
  270.        
  271.       $inf = array();
  272.       list($nam,$val) = explode($spl4, $value);
  273.      
  274.       $nam=implode(' ',array_filter(array_map('trim',explode(' ',str_replace(array("\n","\r")," ",$nam)))));
  275.       $val=implode(' ',array_filter(array_map('trim',explode(' ',str_replace(array("\n","\r")," ",$val)))));
  276.      
  277.       $inf["name"]=$nam;
  278.       $inf["value"]=$val;
  279.      
  280.       return $inf;
  281.    }
  282.    //----------------
  283.    $arr4 = array_map('inff', $arr);
  284.    
  285.    return $arr4;
  286. }
  287.  
  288.      
  289. //-------------------------------------------
  290. //          draw page
  291. //-------------------------------------------
  292. function draw_form() {
  293.    global $fb;
  294. //---------------------
  295. ?>
  296.  
  297. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  298. <html xmlns:fb="http://ogp.me/ns/fb#">
  299.  
  300. <head>
  301. <title>Check page for fb operations</title>
  302.  
  303. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  304. <meta name="description" content="Check page for fb operations" />
  305. <meta name="keywords" content="facebook, api" />
  306.  
  307. <script type="text/javascript" src="jquery.min.js"></script>
  308. <!-- ----------------------------------------- -->
  309. <style type="text/css">
  310.    * {
  311.       margin:0;
  312.       padding:0;
  313.    }
  314.    
  315.    h1 {
  316.       padding:5px;
  317.    }
  318.    
  319.    h3 {
  320.       margin:15px 0 10px 0;
  321.    }
  322.    
  323.    li {
  324.       list-style-type:none;
  325.       margin-bottom:4px;
  326.    }
  327.    
  328.    
  329.    #loginblock {
  330.       font-family: arial, tahoma, sans-serif;
  331.       font-size: 12px;
  332.       word-wrap: break-word;
  333.    }
  334.    
  335.    #loginblock a, #loginblock a:visited {
  336.       display:block;
  337.       padding:5px 0 5px 20px;
  338.       margin: 4px 4px 5px 20px;
  339.       border:solid 1px #888;
  340.       background-color: #f0f0f0;
  341.       text-decoration:none;
  342.       color:#444;
  343.       font-weight:bold;
  344.       width:200px;
  345.       font-size:150%;
  346.    }
  347.    
  348.    #loginblock a:hover {
  349.       background-color:#aaa;
  350.       color:white;
  351.    }
  352.    
  353.    #leftcolumn {
  354.       float:left;
  355.       width:400px;
  356.       background-color:#f5f5f5;
  357.       padding:10px;
  358.      
  359.       font-family: verdana, sans-serif;
  360.       font-size:18px;
  361.      
  362.    }
  363.    
  364.    #leftcolumn a, #leftcolumn a:visited {
  365.       color: #800;
  366.       text-decoration:none;
  367.      
  368.    }
  369.    
  370.    #leftcolumn a:hover {
  371.    
  372.       text-decoration: underline;
  373.    }
  374.    
  375.    #maincontent {
  376.       margin-left:450px;
  377.    }
  378.    
  379.    #ajaxcontent {
  380.       min-height:40px;
  381.       background-color:#fffff0;
  382.    }
  383.    
  384.    #ajaxcontent p {
  385.    
  386.      
  387.    }
  388.    
  389.    #ajaxstatus, #ajaxstatus3 {
  390.       /*min-height:50px;*/
  391.       margin: 5px;
  392.       border: solid 1px #999;
  393.       background-color: #eee;
  394.      
  395.    }
  396.    
  397.    #ajaxstatus p, #ajaxstatus3 p, #ajaxcontent p {
  398.       overflow:hidden;
  399.       border:solid 1px #aaa;
  400.       margin:5px;
  401.       padding:10px;
  402.    }
  403.    
  404.    .remark {
  405.       padding:10px;
  406.       font-size:16px;
  407.       border:solid 4px #888;
  408.       background-color:#f5f5f5;
  409.       margin-top:15px;
  410.       width:500px;
  411.       font-weight:bold;
  412.       word-wrap: break-word;
  413.      
  414.    }
  415.    
  416.    
  417.    #flinfo {
  418.       position:absolute;
  419.       display:none;
  420.       z-index:100;
  421.      
  422.    }
  423.    
  424.    /*--------------------------------*/
  425.    form {
  426.       font-family: tahoma, geneva, sans-serif;
  427.       font-size: 16px;
  428.       color:#926262;
  429.       padding:10px;
  430.    }
  431.    
  432.    fieldset {
  433.       border:1px solid #926262;
  434.       padding:20px;
  435.       padding-left:-1px;
  436.       -webkit-border-radius:5px;
  437.       -moz-border-radius:5px;
  438.       -border-radius:5px;
  439.       -khtml-border-radius:5px;
  440.      
  441.       margin-top:10px;
  442.       margin-bottom:5px;
  443.    }
  444.    
  445.    input[type=checkbox], input[type=radio] {
  446.       display:block;     
  447.       float:left;
  448.       margin-top:5px;
  449.       margin-right:10px;
  450.          
  451.      
  452.    }
  453.    
  454.    input[type=button] {
  455.       padding:10px;
  456.       background:#fea;
  457.       color:red;
  458.       font-weight:bold;
  459.       cursor:pointer;
  460.       border:solid 1px #800;
  461.       -border-radius:5px;
  462.       -moz-border-radius:5px;
  463.       -webkit-border-radius:5px;
  464.    }
  465.    
  466.    label {
  467.       display:block;
  468.       float:left;
  469.       width:260px;
  470.       margin-bottom:10px;
  471.       margin-right:20px;
  472.       text-align:right;
  473.      
  474.    }
  475.    
  476.    legend {
  477.       font-size:1.5em;   
  478.       color:#926262;
  479.       margin-left:20px;
  480.       padding: 5px 10px;
  481.       border: 1px solid #926262;
  482.      
  483.       -webkit-border-radius:5px;
  484.       -moz-border-radius:5px;
  485.       -border-radius:5px;
  486.       -khtml-border-radius:5px;
  487.      
  488.       text-transform:capitalize;
  489.    }
  490.    
  491.    .zrightfld p {
  492.       margin-left: 200px;
  493.    }
  494.    /*--------------------------------*/
  495. </style>
  496.  
  497. <!-- ----------------------------------------- -->
  498. <script type="text/javascript">
  499.  
  500.  
  501.    function print_r(arr, level) {
  502.    
  503.        var print_red_text = "";
  504.        
  505.        if(!level)
  506.           level = 0;
  507.        //--------------------------------  
  508.        var level_padding = "";
  509.        
  510.        for(var j=0; j<level+1; j++)
  511.           level_padding += "    ";
  512.          
  513.        //--------------------------------
  514.        if (typeof(arr) == 'object') {
  515.          
  516.           for (var item in arr) {  
  517.          
  518.              var value = arr[item];          
  519.              if (typeof(value) == 'object') {
  520.                
  521.                 print_red_text += level_padding + "'" + item + "' :\n";
  522.                 print_red_text += print_r(value,level+1);
  523.                  
  524.                 }
  525.              else
  526.                 print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  527.              }
  528.           }  
  529.        else    
  530.           print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
  531.          
  532.     return '<pre>'+print_red_text+'</pre>';
  533.   }
  534.    
  535.    //---------------------------------
  536.    $(document).ready(init);
  537.    
  538.    
  539.    //----------------------------------------------
  540.    //             iframe query
  541.    //----------------------------------------------
  542.    function iframeq(param, command) {
  543.    
  544.       $('#ajaxcontent').empty();
  545.       $('#ajaxcontent').append($('<iframe/>',
  546.       {id:'ziframe', width:'700', height:'400', scrolling: 'no'}));
  547.      
  548.       $('#ziframe').css('border','solid 1px #888');
  549.       $('#ziframe').attr('src',
  550.          "<?='http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]?>"+
  551.          "?ajax&reqtype="+command+'&req='+param);
  552.      
  553.      
  554.        
  555.        
  556.    }
  557.    
  558.    //----------------------------------------------
  559.    //          draw widget
  560.    //----------------------------------------------
  561.    function draw_widget(el) {
  562.    
  563.       var f= $(el).parents('form');
  564.       var sel = f.find('select').get(0);
  565.      
  566.       var ctype = f.find('input[name="ctype"]:checked').attr('value');
  567.      
  568.      
  569.       for (var i=0; i<(sel.options.length); i++) {
  570.      
  571.          if (sel.options[i].selected) {
  572.             var zreq =  sel.options[i].value+'_'+ctype;
  573.            
  574.             el=$('#facebook-jssdk');   
  575.             if ((el).get(0)) {
  576.                el.removeAttr('src');
  577.                el.removeAttr('id');
  578.                
  579.             }
  580.             //----------------------------------------------
  581.             if (!$('#wiframme').get(0)) {
  582.                $('#ajaxcontent').empty();
  583.                
  584.                $('#ajaxcontent').append($('<iframe/>',
  585.                {id:'wiframe', width:"500", height:"400"}));
  586.                
  587.                $('#ajaxcontent').append($('<iframe/>',
  588.                {id:'wiframe3', width:"500", height:"400"}));
  589.                }
  590.              
  591.             //----------------------------------------------  
  592.             $('#wiframe').attr('src',
  593.             "<?='http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"].
  594.             '?ajax&reqtype=drawwidget&req='?>"+zreq);
  595.            
  596.             $('#wiframe').before($('<div/>').append(           
  597.                             $('<a/>', {href   : $('#wiframe').attr('src'),
  598.                                        target : "_blank"
  599.                                      })
  600.                                  .text($('#wiframe').attr('src'))));
  601.                                  
  602.             //----------------------------------------------  
  603.             $('#wiframe3').attr('src',
  604.             "<?='http://'.$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"].
  605.             '?ajax&reqtype=drawwidget&alt3&req='?>"+zreq);
  606.            
  607.             $('#wiframe3').before($('<div/>').append(          
  608.                             $('<a/>', {href   : $('#wiframe3').attr('src'),
  609.                                        target : "_blank"
  610.                                      })
  611.                                  .text($('#wiframe3').attr('src'))));                                
  612.            
  613.             //-----------------------------
  614.             break;
  615.          }       
  616.       }
  617.    }
  618.    //----------------------------------------------
  619.    //             initialization
  620.    //----------------------------------------------
  621.    function init() {
  622.    
  623.       glTime=0;
  624.       //---------------------------
  625.       load_fql_list();
  626.    
  627.       //---------------------------widget select list
  628.      
  629.       var optarr = ['login','activity','comments','facepile','likebox',
  630.                     'likebutton','recommendbar','recommendbox',
  631.                     '_registration','sendbutton','_sharelinks','sharedactivity',
  632.                     'subscribebutton'];
  633.                    
  634.       var type_arr = ['html5','opengraph','iframe', 'link'];       
  635.      
  636.       var sel=$('form[name="fdrawwidget"] select').get(0);
  637.      
  638.       for (var i=0; i<optarr.length; i++) {
  639.          var opt = new Option (optarr[i]+' widget', optarr[i], false, false);
  640.          
  641.          try {
  642.             sel.add(opt, null);
  643.            
  644.          } catch (e) {
  645.          
  646.             sel.add(opt);
  647.          }
  648.          
  649.       }
  650.      
  651.       var frmz = $(sel).parents('form');
  652.       frmz.find('input[type=button]').before($('<fieldset/>'));
  653.       frmz.find('fieldset:last').append($('<legend/>').text('code type'));
  654.      
  655.       var tmpf = frmz.find('fieldset:last');
  656.      
  657.       for (var i=0; i<type_arr.length; i++) {
  658.      
  659.          var tmpp = tmpf.append($('<p/>').text(type_arr[i])).find('p:eq('+i+')');
  660.          tmpp.prepend($('<input/>',{type:'radio',name:'ctype',value:type_arr[i]}));
  661.       }
  662.      
  663.       tmpf.find('input[type=radio]:first').attr('checked',true);
  664.      
  665.      
  666.       //---------------------------
  667.       $('#leftcolumn h3').css({cursor:'pointer'}).click( function()
  668.          {$(this).next('ul').slideToggle('fast');}
  669.       )
  670.       //---------------------------
  671.       $('form[name=paramform] input[type="checkbox"]').change(                           
  672.               function() {                   
  673.                      var curel = this;
  674.                      
  675.                      $(this).parent().children('input').each(
  676.                         function(index) {
  677.                            
  678.                            if (this!==curel) {
  679.                               $(this).removeAttr('checked');
  680.                            }
  681.                         }
  682.                      )
  683.                   }
  684.                )
  685.                
  686.       //------------------------------------------------------------------     
  687.       //                  Graph API Requests
  688.       //------------------------------------------------------------------
  689.       $('#operationslist a').each(
  690.          function(i) {
  691.          
  692.             $(this).click(function() {
  693.                        
  694.                //-----------------------
  695.                var inp = $('form[name=paramform] input[name=crtab]');
  696.                var outtype =
  697.                   $('form[name=paramform] fieldset:last input[name="outtype"]:checked').attr('value');
  698.                            
  699.                if ((inp.attr('checked')!==undefined) && (inp.attr('checked')!==false))
  700.                
  701.                   //---------------creating table
  702.                  
  703.                   req_createtable($(this).attr('rel'),'mktab');
  704.                else
  705.                   //---------------------filling table
  706.                  
  707.                   if (inp.nextAll('input').first().attr('checked')==='checked')
  708.                      
  709.                      req_createtable($(this).attr('rel'),'filltab');
  710.                          
  711.                   else
  712.                      //------------------show table for current user
  713.                      
  714.                      if (inp.nextAll('input').eq(1).attr('checked')==='checked') {
  715.                      
  716.                         if (outtype=='zlist')                      
  717.                            req_createtable($(this).attr('rel'), 'showcurr_list');
  718.                         else
  719.                            req_createtable($(this).attr('rel'), 'showcurr' );
  720.                            
  721.                     } else                       
  722.                         //-------------------show table for all users
  723.                        
  724.                         if (inp.nextAll('input').eq(2).attr('checked')==='checked') {
  725.                        
  726.                            if (outtype=='zlist')
  727.                               req_createtable($(this).attr('rel'),'showall_list');
  728.                            else
  729.                               req_createtable($(this).attr('rel'),'showall');
  730.                              
  731.                         } else
  732.                            //-----------------graph api request
  733.                            
  734.                            ajax_request($(this).attr('rel'),'apigraph');
  735.                
  736.             });
  737.            
  738.             $(this).text('load '+$(this).attr('rel'));
  739.             //alert $(this);
  740.          })
  741.          
  742.          //------------------------------------------------------------------
  743.          //                        custom tables
  744.          //------------------------------------------------------------------
  745.          $('#operationslist4 a').each(
  746.             function(i) {
  747.            
  748.                $(this).click( function() {
  749.                
  750.                   var inp3 = $('form[name=paramform] input[name=showcurr]');
  751.                   var inp4 = $('form[name=paramform] input[name=showall]');
  752.                   var outtype =
  753.                      $('form[name=paramform] fieldset:last input[name="outtype"]:checked').attr('value');
  754.                  
  755.                   //--------------------------------  
  756.                   if ((inp3.attr('checked')!==undefined) && (inp3.attr('checked')!==false)) {
  757.                
  758.                      if (outtype=='zlist')
  759.                         req_createtable($(this).attr('rel'), 'showcustom_list');
  760.                      else
  761.                         req_createtable($(this).attr('rel'), 'showcustom');
  762.                   }
  763.                
  764.                   //--------------------------------  
  765.                   if ((inp4.attr('checked')!==undefined) && (inp4.attr('checked')!==false)) {
  766.                  
  767.                      if (outtype=='zlist')
  768.                         req_createtable($(this).attr('rel'), 'showcustomall_list');
  769.                      else
  770.                         req_createtable($(this).attr('rel'), 'showcustomall');
  771.                    }
  772.                })
  773.                
  774.                $(this).text('show '+$(this).attr('rel'));
  775.             }
  776.          )
  777.          
  778.          
  779.       //-----------  AjaxStart, AjaxStop, AjaxSend, AjaxSuccess, AjaxError, AjaxComplete events
  780.      
  781.       //---------------------------------------  
  782.       //     ajaxStart   
  783.       //---------------------------------------  
  784.       $('#ajaxstatus').ajaxStart(
  785.           function() {
  786.              $(this).html('Request started. Please wait...');
  787.           })
  788.          
  789.       //---------------------------------------  
  790.       //    ajaxStop
  791.       //---------------------------------------      
  792.       $('#ajaxstatus').ajaxStop(
  793.           function() {
  794.              $(this).html('Request finished');
  795.           } )    
  796.      
  797.        //---------------------------------------     
  798.        //     ajaxSend
  799.        //---------------------------------------     
  800.        $('#ajaxstatus3').ajaxSend (
  801.        
  802.           function(ev, jqXHR, options) {   
  803.          
  804.              $(this).empty();
  805.              $(this).append($('<p/>').html('<b>triggered ajaxSend</b>'));
  806.              
  807.              $(this).append($('<p/>').html('ajaxResponse: <pre>'+jqXHR.responseText+'</pre>'));
  808.              $(this).append($('<p/>').html('status: '+jqXHR.status+'<br/>ready state:'+jqXHR.readyState));
  809.              
  810.              //---------------------------
  811.              $(this).append(
  812.                 $('<p>', {class:'info'}).html('ev: <br/>'/*+print_r(ev)*/));
  813.              
  814.              $(this).append(
  815.                 $('<p>', {class:'info'}).html('jqXHR: <br/>'+print_r(jqXHR))
  816.                    .css({'height':'50px', 'cursor':'pointer'})
  817.                    .click(function() {
  818.                      
  819.                       if ($(this).height()<800)
  820.                          $(this).animate({'height':'800px'},"fast");
  821.                       else
  822.                          $(this).animate({'height':'50px'},"fast");
  823.                    }));
  824.                
  825.            
  826.              $(this).append($(document.createElement('P'))
  827.                          .html('options: <br/>' +print_r(options))
  828.                          .css({'height':'50px', 'cursor':'pointer'})
  829.                          .click(function() {
  830.                             if ($(this).height()<800)
  831.                                $(this).animate({'height':'800px'},"fast");
  832.                             else
  833.                                $(this).animate({'height':'50px'},"fast");
  834.                          }));                    
  835.           }
  836.        )
  837.        
  838.        //---------------------------------------     
  839.        //     ajaxSuccess
  840.        //---------------------------------------
  841.        $('#ajaxstatus3').ajaxSuccess(
  842.        
  843.           function (ev, jqXHR, options) {
  844.              $(this).append($('<p/>').html('<b>triggered ajaxSuccess</b>'));
  845.              
  846.               //$(this).append($('<p/>').html('ajaxResponse: <pre>'+jqXHR.responseText+'</pre>'));
  847.               $(this).append($('<p/>').html('status: '+jqXHR.status+'<br/>ready state:'+jqXHR.readyState));
  848.           }
  849.        );
  850.        
  851.        //---------------------------------------     
  852.        //     ajaxError
  853.        //---------------------------------------
  854.        $('#ajaxstatus3').ajaxError(
  855.        
  856.           function (ev, jqXHR, options, exception) {
  857.              $(this).append($('<p/>').html('<b>triggered ajaxError</b>'));
  858.              
  859.               $(this).append($('<p/>').html('ajaxResponse: <pre>'+jqXHR.responseText+'</pre>'));
  860.               $(this).append($('<p/>').html('status: '+jqXHR.status+'<br/>ready state:'+jqXHR.readyState));
  861.               $(this).append($('<p/>').html('exception: '+exception));
  862.           }
  863.        );
  864.        
  865.        
  866.        //---------------------------------------     
  867.        //     ajaxComplete
  868.        //---------------------------------------
  869.        $('#ajaxstatus3').ajaxComplete(
  870.        
  871.           function (ev, jqXHR, options) {
  872.              $(this).append($('<p/>').html('<b>triggered ajaxComplete</b>'));
  873.              
  874.               //$(this).append($('<p/>').html('ajaxResponse: <pre>'+jqXHR.responseText+'</pre>'));
  875.               $(this).append($('<p/>').html('status: '+jqXHR.status+'<br/>ready state:'+jqXHR.readyState));
  876.           }
  877.        );
  878.      
  879.      
  880.    }
  881.  
  882.    
  883.    //-------------------------------------------------------
  884.    //                 local events
  885.    //-------------------------------------------------------
  886.    //-------------------------------------------------------
  887.    //         onSuccess
  888.    //-------------------------------------------------------
  889.    function onSuccess(inf, textStatus, jqXHR) {
  890.    
  891.      var a = $('#ajaxstatus3');
  892.      
  893.      a.append($('<p/>').html('<font color="red"><b>triggered local success</b></font>'));
  894.      //a.append($('<p/>').html('ajaxResponse: <pre>'+jqXHR.responseText+'</pre>'));
  895.      a.append($('<p/>').html('status: '+jqXHR.status+'<br/>ready state:'+jqXHR.readyState));
  896.      a.append($('<p/>').html('textStatus: '+textStatus));
  897.    
  898.    
  899.       var s='';
  900.       //--------------------
  901.       function get_obj(objel, deep) {
  902.      
  903.           var s3= new Array(deep*3).join('&nbsp;');
  904.          
  905.           for (var el in objel) {
  906.            
  907.               s3+=typeof(objel[el])+' : '+el+' = '
  908.              
  909.               if (typeof(objel[el])=='object')
  910.              
  911.                   s3+=String.fromCharCode(13)+String.fromCharCode(10)+
  912.                        get_obj(objel[el], deep+1);
  913.                else {
  914.                   s3+= objel[el]+String.fromCharCode(13)+String.fromCharCode(10);
  915.                   }
  916.          }
  917.          return s3;
  918.      
  919.       }
  920.       //--------------------
  921.       s=get_obj(inf,0);
  922.      
  923.       var tnode = $('#ajaxcontent');
  924.       tnode.empty();
  925.      
  926.       tnode.append($(document.createElement('P')));
  927.       tnode.children('p').filter(':eq(0)').html('<b>'+textStatus+'</b>');
  928.  
  929.       tnode.append($('<p/>').html('<pre>'+s+'</pre>'));
  930.      
  931.       tnode.append($('<p>', {class: 'zinfo'}).html('XHR:<br/>'+print_r(jqXHR)));
  932.      
  933.      
  934.    }
  935.    
  936.    //-------------------------------------------------------
  937.    //         onError
  938.    //-------------------------------------------------------
  939.    function onError(xhr, status, exception) {
  940.    
  941.      var a = $('#ajaxstatus3');
  942.      
  943.      a.append($('<p/>').html('<font color="red"><b>triggered local error</b></font>'));
  944.      a.append($('<p/>').html('ajaxResponse: <pre>'+xhr.responseText+'</pre>'));
  945.      a.append($('<p/>').html('status: '+xhr.status+'<br/>ready state:'+xhr.readyState));
  946.      a.append($('<p/>').html('textStatus: '+status));
  947.      a.append($('<p/>').html('Exception: '+exception));
  948.      
  949.    }
  950.    
  951.    //-------------------------------------------------------
  952.    //         onBeforeSend
  953.    //-------------------------------------------------------
  954.    
  955.    function onBeforeSend(xhr, settings) {
  956.    
  957.      var tnode = $('#ajaxcontent');
  958.      tnode.html('please wait...');
  959.    
  960.      var a = $('#ajaxstatus3');
  961.      a.empty();
  962.      a.append($('<p/>').html('<font color="red"><b>triggered local beforeSend</b></font>'));
  963.      a.append($('<p/>').html('ajaxResponse: <pre>'+xhr.responseText+'</pre>'));
  964.      a.append($('<p/>').html('status: '+xhr.status+'<br/>ready state:'+xhr.readyState));
  965.      //a.append($('<p/>').html('settings: '+print_r(settings)));
  966.    }
  967.    
  968.    //-------------------------------------------------------
  969.    //         onComplete
  970.    //-------------------------------------------------------
  971.    function onComplete(xhr, status) {
  972.    
  973.      var a = $('#ajaxstatus3');
  974.      
  975.      a.append($('<p/>').html('<font color="red"><b>triggered local complete</b></font>'));
  976.      //a.append($('<p/>').html('ajaxResponse: <pre>'+xhr.responseText+'</pre>'));
  977.      a.append($('<p/>').html('status: '+xhr.status+'<br/>ready state:'+xhr.readyState));
  978.      a.append($('<p/>').html('textStatus: '+status));
  979.    }
  980.    
  981.    
  982.    //-------------------------------------------------------
  983.    //            ajax request
  984.    //-------------------------------------------------------
  985.    
  986.    function ajax_request(param, reqtypeval) {
  987.    
  988.       $.ajaxSetup( {
  989.      
  990.          type: 'POST',
  991.          url: "<?php echo $_SERVER["PHP_SELF"]?>",
  992.          dataType: 'json',
  993.          processData: true,
  994.          cache: false,
  995.          timeout: 50000,
  996.          
  997.          username: '',
  998.          password: '',
  999.          ifModified: false,
  1000.          global: true,
  1001.          crossDomain: false,
  1002.       })
  1003.      
  1004.       //----------------------------
  1005.       $.ajax (
  1006.          {
  1007.             data: {ajax:'',
  1008.                   reqtype:reqtypeval,
  1009.                   req: param},
  1010.        
  1011.             //-----------------
  1012.             beforeSend: onBeforeSend,
  1013.             success: onSuccess,
  1014.             error: onError,
  1015.            
  1016.             complete: onComplete,
  1017.            
  1018.             statusCode: {
  1019.                404: function() {
  1020.                
  1021.                   var tnode = $('#ajaxcontent');
  1022.                   tnode.html
  1023.                }
  1024.             }
  1025.            
  1026.            
  1027.          
  1028.          })
  1029.    
  1030.    }
  1031.  
  1032.    //-------------------------------------------------------
  1033.    //            load fql list
  1034.    //-------------------------------------------------------
  1035.    
  1036.    function onGetSuccess (data, status, xhr) {
  1037.       el = $('#operationslist3');
  1038.      
  1039.       $.each(data, function (i, valu) {
  1040.          var lii=$('<li/>');
  1041.          
  1042.          var a = $('<a/>');
  1043.  
  1044.          a.text(valu["name"]);
  1045.          a.attr('href','#');
  1046.          
  1047.          //-----------------------------
  1048.          a.click(
  1049.             //------------
  1050.             {fqlval: valu["value"]},
  1051.             //------------
  1052.             function(ev) {
  1053.            
  1054.                var inp = $('form[name=paramform] input[name=crtab]');
  1055.                var outtype =
  1056.                   $('form[name=paramform] fieldset:last input[name="outtype"]:checked').attr('value');
  1057.                
  1058.                
  1059.                if ((inp.attr('checked')!==undefined) && (inp.attr('checked')!==false))
  1060.                
  1061.                   //-----------------creating table    
  1062.                  
  1063.                   req_createtable(ev.data.fqlval, 'mkfqltab');               
  1064.                else
  1065.                   //----------------------filling table
  1066.                  
  1067.                   if (inp.nextAll('input').first().attr('checked')==='checked')
  1068.                                          
  1069.                      req_createtable(ev.data.fqlval,'fillfqltab');                   
  1070.                   else                   
  1071.                      //------------------------show table for current user
  1072.                      
  1073.                      if (inp.nextAll('input').eq(1).attr('checked')==='checked') {
  1074.                        
  1075.                         if (outtype=='zlist')
  1076.                            req_createtable(ev.data.fqlval, 'showfqlcurr_list');
  1077.                         else
  1078.                            req_createtable(ev.data.fqlval, 'showfqlcurr');
  1079.                            
  1080.                         }
  1081.                      else
  1082.                         //--------------------show table for all users
  1083.                        
  1084.                         if (inp.nextAll('input').eq(2).attr('checked')==='checked') {
  1085.                            
  1086.                            if (outtype=='zlist')
  1087.                               req_createtable(ev.data.fqlval, 'showfqlall_list');
  1088.                            else
  1089.                               req_createtable(ev.data.fqlval, 'showfqlall');
  1090.                         }
  1091.                         else
  1092.                            //-------------------fql request
  1093.                            
  1094.                            ajax_request(ev.data.fqlval,'fql'); 
  1095.                  
  1096.                return false;
  1097.             });
  1098.            
  1099.         //-----------------------------
  1100.         a.data('fqv',valu["value"]);
  1101.        
  1102.         a.hover (
  1103.  
  1104.          function(ev) {
  1105.             //$(this).after($('<p/>',{class:'remark'}).text($(this).data('fqv')));
  1106.             //alert (ev.clientX);
  1107.            
  1108.            
  1109.             clearTimeout(glTime);
  1110.                
  1111.             $('#flinfo').text($(this).data('fqv'))
  1112.                .clearQueue()
  1113.                .addClass('remark')
  1114.                .css('left',ev.clientX+100)
  1115.                .css('top',ev.clientY+
  1116.                   ((document.documentElement && document.documentElement.scrollTop) ||
  1117.                   (document.body && document.body.scrollTop) || 0)-100)
  1118.                .fadeIn("fast");
  1119.            
  1120.          },
  1121.          
  1122.          function(ev) {
  1123.             //$(this).next('p').remove();
  1124.             glTime= setTimeout( function() {
  1125.             $('#flinfo').fadeOut("slow")
  1126.                .queue(
  1127.                   function() {
  1128.                      $(this).removeClass('remark');
  1129.                      $(this).dequeue();
  1130.                      })}, 1000);
  1131.                      
  1132.          }
  1133.    
  1134.         )
  1135.                  
  1136.          lii.append(a);
  1137.          el.append(lii);
  1138.       });
  1139.    }
  1140.    
  1141.    //--------------------------------------------  
  1142.    function load_fql_list() {
  1143.    
  1144.       $inf = $.get( "<?php echo $_SERVER["PHP_SELF"]?>",
  1145.                     {ajax:'', reqtype:'getfqls'},
  1146.                     onGetSuccess,
  1147.                     'json');
  1148.                    
  1149.    }
  1150.    
  1151.    //------------------------------------------------------------  
  1152.    //      create table  - request
  1153.    //------------------------------------------------------------
  1154.  
  1155.    function onPostSuccess (data, status, xhr) {
  1156.    
  1157.       var tnode =$('#ajaxcontent');
  1158.      
  1159.       tnode.empty();
  1160.      
  1161.       tnode.append($('<p/>').text('status: '+status));
  1162.       tnode.append($('<p/>').html(data));
  1163.    }
  1164.    
  1165.    
  1166.    //-------------------------------------------------------
  1167.    function req_createtable (param, command) {
  1168.    
  1169.       var tnode =$('#ajaxcontent');  
  1170.       tnode.empty();
  1171.      
  1172.       $inf = $.post("<?php echo $_SERVER["PHP_SELF"]?>",
  1173.                         {ajax:'',
  1174.                          reqtype: command,
  1175.                          req: param},
  1176.                          
  1177.                          onPostSuccess,
  1178.                          'text'
  1179.                          );
  1180.    
  1181.       return $inf; 
  1182.                          
  1183.    }  
  1184.    
  1185.    //------------------------------------------------------------
  1186.    //        simple get request
  1187.    //------------------------------------------------------------
  1188.    
  1189.    function onGetSuccess4(data, status, xhr) {
  1190.    
  1191.       var tnode = $('#ajaxcontent');
  1192.      
  1193.       tnode.append($('<p/>').text('status: '+status));
  1194.       tnode.append($('<p/>').html(data));
  1195.    }
  1196.    
  1197.    //------------------------------------------------------
  1198.    function ajax_get(param, command) {
  1199.    
  1200.       var tnode = $('#ajaxcontent');
  1201.       tnode.empty();
  1202.      
  1203.       $inf = $.get("<?php echo $_SERVER["PHP_SELF"]?>",
  1204.                      { ajax:'',
  1205.                        reqtype: command,
  1206.                        req: param},
  1207.                        
  1208.                        onGetSuccess4,
  1209.                        'text');
  1210.       return $inf;             
  1211.    }
  1212.    
  1213.  
  1214.    
  1215. </script>
  1216. <!-- ------------------------------------------ -->
  1217.  
  1218. </head>
  1219.  
  1220. <body>
  1221.  
  1222.    <div id="flinfo">
  1223.    </div>
  1224.    <h1>Test fb operational page</h1>
  1225.    <div id="loginblock">
  1226.    <?php
  1227.     //echo '<pre>'.print_r($_SESSION,true).'</pre>';
  1228.    
  1229.    
  1230.    if (!$fb->connected()) {
  1231.       echo   "<a href=\"$fb->loginUrl\">Login</a>";
  1232.       //echo $fb->drawLogin(true);
  1233.    }
  1234.    else {
  1235.       echo   "<a href=\"$fb->logoutUrl\">Logout</a>";
  1236.  
  1237.    }  
  1238.    ?>
  1239.    </div>
  1240.    
  1241.    <div id="leftcolumn">
  1242.    
  1243.    <h3>Operations</h3>
  1244.    <a href='#' onclick="iframeq('','relatedusers');return false;">Related users: collect info</a><br/>
  1245.    <a href='#' onclick="ajax_get('','relatedusers4');return false;">Related users: Show info</a><br/>
  1246.    <a href='#' onclick="ajax_get('','relatedusers5');return false;">Related users: Result page</a><br/>
  1247.    <a href='#' onclick="ajax_get('','likestofql');return false;">Service: likes:base-&gt;fb_user</a>
  1248.    
  1249.    <h3>Utils</h3>
  1250.    <a href='#' onclick="ajax_request('','getfqls');return false;">list of fqls</a>
  1251.    
  1252.    <form name="fdrawwidget">
  1253.      <fieldset>
  1254.      <legend>draw facebook widget</legend>
  1255.       <select>
  1256.       </select>
  1257.       <input type="button" onclick="draw_widget(this);" value="draw" />
  1258.       </fieldset>
  1259.    </form>
  1260.    
  1261.    <form name="paramform">
  1262.       <fieldset>
  1263.          <legend>commands</legend>
  1264.          <label for="crtab">create table for node</label>
  1265.          <input type="checkbox" name="crtab" />
  1266.          
  1267.           <label for="filltab">fill table for node</label>
  1268.           <input type="checkbox" name="filltab" />
  1269.          
  1270.           <label for="showcurr">show contents (current user) </label>
  1271.           <input type="checkbox" name="showcurr" />
  1272.          
  1273.           <label for="showall">show contents (all) </label>
  1274.           <input type="checkbox" name="showall" />
  1275.       </fieldset>
  1276.      
  1277.       <fieldset class="zrightfld">
  1278.          <p><input type="radio" name="outtype" value="ztable" checked />output table</p>
  1279.          <p><input type="radio" name="outtype" value="zlist" />output list</p>
  1280.          
  1281.       </fieldset>
  1282.    </form>
  1283.    
  1284.    <h3>Custom tables</h3>
  1285.    <ul id="operationslist4">
  1286.       <li><a href="#" rel="fbs_likes_users"></a></li>
  1287.    </ul>
  1288.    
  1289.    <h3>Api graph requests</h3>
  1290.    <ul id="operationslist">
  1291.           <li><a href="#" rel="me"></a></li>
  1292.       <li><a href="#" rel="me/accounts"></a></li>
  1293.       <li><a href="#" rel="me/achievements"></a></li>
  1294.       <li><a href="#" rel="me/activities"></a></li>
  1295.       <li><a href="#" rel="me/albums"></a></li>
  1296.       <li><a href="#" rel="me/apprequests"></a></li>
  1297.       <li><a href="#" rel="me/books"></a></li>
  1298.       <li><a href="#" rel="me/checkins"></a></li>
  1299.       <li><a href="#" rel="me/events"></a></li>
  1300.       <li><a href="#" rel="me/family"></a></li>
  1301.       <li><a href="#" rel="me/friendlists"></a></li>
  1302.       <li><a href="#" rel="me/friendrequests"></a></li>
  1303.       <li><a href="#" rel="me/friends"></a></li>
  1304.       <li><a href="#" rel="me/games"></a></li>
  1305.       <li><a href="#" rel="me/groups"></a></li>
  1306.       <li><a href="#" rel="me/home"></a></li>
  1307.       <li><a href="#" rel="me/inbox"></a></li>
  1308.       <li><a href="#" rel="me/interests"></a></li>
  1309.       <li><a href="#" rel="me/likes"></a></li>
  1310.       <li><a href="#" rel="me/links"></a></li>
  1311.       <li><a href="#" rel="me/locations"></a></li>
  1312.       <li><a href="#" rel="me/movies"></a></li>
  1313.       <li><a href="#" rel="me/music"></a></li>
  1314.       <li><a href="#" rel="me/mutualfriends"></a></li>
  1315.       <li><a href="#" rel="me/notes"></a></li>
  1316.       <li><a href="#" rel="me/notifications"></a></li>
  1317.       <li><a href="#" rel="me/outbox"></a></li>
  1318.       <li><a href="#" rel="me/payments"></a></li>
  1319.       <li><a href="#" rel="me/permissions"></a></li>
  1320.       <li><a href="#" rel="me/photos"></a></li>
  1321.       <li><a href="#" rel="me/photos/uploaded"></a></li>
  1322.       <li><a href="#" rel="me/picture"></a></li>
  1323.       <li><a href="#" rel="me/pokes"></a></li>
  1324.       <li><a href="#" rel="me/posts"></a></li>
  1325.       <li><a href="#" rel="me/questions"></a></li>
  1326.       <li><a href="#" rel="me/scores"></a></li>
  1327.       <li><a href="#" rel="me/sharedposts"></a></li>
  1328.       <li><a href="#" rel="me/statuses"></a></li>
  1329.       <li><a href="#" rel="me/subscribedto"></a></li>
  1330.       <li><a href="#" rel="me/subscribers"></a></li>
  1331.       <li><a href="#" rel="me/tagged"></a></li>
  1332.       <li><a href="#" rel="me/television"></a></li>
  1333.       <li><a href="#" rel="me/updates"></a></li>
  1334.       <li><a href="#" rel="me/videos"></a></li>
  1335.      
  1336.    </ul>
  1337.    
  1338.    <h3>Fql requests</h3>
  1339.    <ul id="operationslist3">
  1340.      
  1341.      
  1342.    </ul>
  1343.    </div>
  1344.    <div id="maincontent">
  1345.    
  1346.       <div id="ajaxcontent"></div>  
  1347.       <div id="ajaxstatus"></div>
  1348.       <div id="ajaxstatus3"></div>
  1349.    </div>
  1350. </body>
  1351. </html>
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357. <?php
  1358. //--------------------
  1359.  
  1360. }
  1361.    
  1362.  
  1363. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement