Advertisement
Guest User

Fixes for FBShare

a guest
Jun 9th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.48 KB | None | 0 0
  1. To make the table display properly
  2. From:
  3. function parse_analytics($source){
  4.  
  5.     //echo ($source);
  6.     $resp = _fetch_remote_file($source);   
  7.     $resp_result = $resp->results;
  8.  
  9.     if ( !function_exists('xml_parser_create') )
  10.             trigger_error( "Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php" );
  11.  
  12.     $parser = xml_parser_create();
  13.  
  14.     if ( !is_resource($parser) ) {
  15.             trigger_error( "Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php");
  16.             }
  17.  
  18.     ?>
  19.  
  20.     <table class="widefat post fixed" cellspacing="0" cellpadding="0" border=1>
  21.                 <thead>
  22.                     <tr>
  23.                         <th style="width: 50%;">URL</th>
  24.                         <th style="width: 10%;">Share Counts</th>
  25.                         <th style="width: 10%;">Like Counts</th>
  26.                         <th style="width: 10%;">Comment Counts</th>
  27.                         <th style="width: 10%;">Total Counts</th>
  28.                         <th style="width: 10%;">Click Counts</th>
  29.                     </tr>
  30.              </thead>
  31.     <?php
  32.  
  33.     xml_set_element_handler($parser, "startElementHandler", "endElementHandler");
  34.     xml_set_character_data_handler($parser, "characterDataHandler");
  35.     $status = xml_parse( $parser, $resp_result );
  36.     xml_parser_free( $parser );
  37.  
  38. }
  39. To:
  40.  
  41. function parse_analytics($source){
  42.  
  43.     //echo ($source);
  44.     $resp = _fetch_remote_file($source);   
  45.     $resp_result = $resp->results;
  46.    
  47.  
  48.     if ( !function_exists('xml_parser_create') )
  49.             trigger_error( "Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php" );
  50.  
  51.     $parser = xml_parser_create();
  52.  
  53.     if ( !is_resource($parser) ) {
  54.             trigger_error( "Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php");
  55.             }
  56.  
  57.     ?>
  58.  
  59.  
  60.     <?php
  61.  
  62.     xml_set_element_handler($parser, "startElementHandler", "endElementHandler");
  63.     xml_set_character_data_handler($parser, "characterDataHandler");
  64.     $status = xml_parse( $parser, $resp_result );
  65.     xml_parser_free( $parser );
  66.  
  67. }
  68.  
  69. To load data for every 20 links:
  70. From:
  71. function fb_stats_page() {
  72.  
  73. ?>
  74.  
  75.      <div class="wrap" style="font-size:13px;">
  76.             <div class="icon32" id="icon-options-general"><br/></div><h2>Settings for Facebook Share Integration</h2>
  77.             <div id="fb_canvas" style="width:800px;float:left">
  78.         </div>
  79.  
  80.         <?php
  81.  
  82.         //The Query
  83.         query_posts( 'post_type=post&posts_per_page=-1&orderby=title&order=ASC');
  84.  
  85.  
  86.         //The Loop
  87.         $urls = '';
  88.         if ( have_posts() ) : while ( have_posts() ) : the_post();
  89.           if (get_post_status($post->ID) == 'publish') {
  90.                 $urls .= get_permalink().",";
  91.           }
  92.     ?>
  93.          <?php
  94.         endwhile; endif;
  95.  
  96.         //Reset Query
  97.         wp_reset_query();
  98.         query_posts( 'post_type=page&posts_per_page=-1&orderby=title&order=ASC');
  99.         //The Loop (Fix from RPG84 - http://wordpress.org/support/topic/plugin-facebook-share-new-some-fixes-for-the-statistics-page?replies=1)
  100.         if ( have_posts() ) : while ( have_posts() ) : the_post();
  101.         if (get_post_status($post->ID) == 'publish') {
  102.             $urls .= get_permalink().",";
  103.             }
  104.         endwhile; endif;
  105.        
  106.        
  107.         $get_analytics = fb_read_analytics($urls);
  108.         echo "</table>";
  109.      }  
  110.  
  111. To:
  112. function fb_stats_page() {
  113.  
  114. ?>
  115.  
  116.      <div class="wrap" style="font-size:13px;">
  117.             <div class="icon32" id="icon-options-general"><br/></div><h2>Settings for Facebook Share Integration</h2>
  118.             <div id="fb_canvas" style="width:800px;float:left">
  119.         </div>
  120.     <table class="widefat post fixed" cellspacing="0" cellpadding="0" border=1>
  121.                 <thead>
  122.                     <tr>
  123.                         <th style="width: 50%;">URL</th>
  124.                         <th style="width: 10%;">Share Counts</th>
  125.                         <th style="width: 10%;">Like Counts</th>
  126.                         <th style="width: 10%;">Comment Counts</th>
  127.                         <th style="width: 10%;">Total Counts</th>
  128.                         <th style="width: 10%;">Click Counts</th>
  129.                     </tr>
  130.              </thead>
  131.         <?php
  132.  
  133.         //The Query
  134.         query_posts( 'post_type=post&posts_per_page=-1&orderby=title&order=ASC');
  135.  
  136.  
  137.         //The Loop
  138.         $urls = '';
  139.         $counturl = '';
  140.         if ( have_posts() ) : while ( have_posts() ) : the_post();
  141.           if (get_post_status($post->ID) == 'publish') {
  142.                 if($counturl<='20' ){
  143.                 $urls .= get_permalink().",";
  144.                 $counturl++;
  145.             } else {
  146.                 $get_analytics = fb_read_analytics($urls);
  147.                 $urls = get_permalink().",";
  148.                 $counturl='';
  149.             }          
  150.           }
  151.     ?>
  152.          <?php
  153.         endwhile; endif;
  154.  
  155.         //Reset Query
  156.         wp_reset_query();
  157.         query_posts( 'post_type=page&posts_per_page=-1&orderby=title&order=ASC');
  158.         //The Loop (Fix from RPG84 - http://wordpress.org/support/topic/plugin-facebook-share-new-some-fixes-for-the-statistics-page?replies=1)
  159.         if ( have_posts() ) : while ( have_posts() ) : the_post();
  160.         if (get_post_status($post->ID) == 'publish') {
  161.                 if($counturl<='20' ){
  162.                 $urls .= get_permalink().",";
  163.                 $counturl++;
  164.             } else {
  165.                 $get_analytics = fb_read_analytics($urls);
  166.                 $urls = get_permalink().",";
  167.                 $counturl='';
  168.             }
  169.             }
  170.         endwhile; endif;
  171.        
  172.        
  173.         $get_analytics = fb_read_analytics($urls);
  174.         echo "</table>";
  175.      }  
  176.  
  177.  
  178.  
  179.  
  180. This will give the counts different colors:
  181. From:
  182. function characterDataHandler ($parser, $cdata) {
  183.  
  184.     global $write;
  185.  
  186.     if ($write==1){
  187.         echo('<td>'.$cdata.'</td>');
  188.     }
  189.  
  190. }
  191. To:
  192. function characterDataHandler ($parser, $cdata) {
  193.  
  194.     global $write;
  195.  
  196.     if ($write==1){
  197.         if($cdata>"0" && $cdata<"10"){
  198.         echo('<td><font color="#FBB117"><b>'.$cdata.'</b></font></td>');
  199.         }elseif(is_numeric($cdata) && $cdata>="10"){
  200.         echo('<td><font color="#4CC417"><b>'.$cdata.'</b></font></td>');
  201.         }elseif($cdata=="0"){
  202.         echo('<td><font color="#E42217"><b>'.$cdata.'</b></font></td>');
  203.         }else{
  204.         echo('<td>'.$cdata.'</td>');
  205.         }
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement