1. <?php
  2.  
  3. function tp_header(){
  4.  
  5.     echo '<style type="text/css">#content{float:left;}</style>';
  6.  
  7. }
  8.  
  9.  
  10.  
  11. /*********************************************************************************************/
  12.  
  13. $tp_credit_footer = 'Supplied by <a href="http://www.apps4rent.com/virtual-dedicated-private-server-windows-hyper-v-vds-vs-vps-hosting/virtual-dedicated-server.html" target="_blank">Virtual Dedicated Server</a>, Firehost <a href="http://www.firehost.com/" title="Managed hosting" target="_blank">Managed Hosting</a>, <a href="http://www.Virtual-dedicated.net" target="_blank">VPS Hosting</a>';
  14.  
  15. $tp_credit_footer_HomeOnly=FALSE; /* FALSE or TRUE : TRUE will show only home/front page ( include page 2,3,4... ); FALSE show on every pages */
  16.  
  17.  
  18.  
  19. /*
  20.  
  21. Text: <li><h4>Theme Credit</h4><div class="textwidget"> content </div></li>
  22.  
  23. List: <li><h4>Theme Credit</h4><ul> list with li </ul></li>
  24.  
  25. mix : <li><h4>Theme Credit</h4><ul> list with li </ul><div class="textwidget"> content </div></li>
  26.  
  27. $tp_credit_sb_home  and $tp_credit_sb_inner : won't show is leave blank ''
  28.  
  29. */
  30.  
  31.  
  32.  
  33. $tp_credit_sb_home  = '<li><h4>Theme Credit</h4><ul>'.
  34.  
  35. '<li><a href="http://www.themegrade.com/" title="Wordpress Themes" target="_blank">Wordpress Theme</a></li>'.
  36.  
  37. '<li><a href="http://www.drtanandpartners.com/" title="Singapore Clinic" target="_blank">Clinic Singapore</a></li>'.
  38.  
  39. '</ul></li>';
  40.  
  41.  
  42.  
  43. $tp_credit_sb_inner = '<li><h4>Theme Credit</h4><ul>'.
  44.  
  45. '<li><a href="http://www.drtanandpartners.com/" title="Singapore Clinic" target="_blank">Clinic Singapore</a></li>'.
  46.  
  47. '</ul></li>';
  48.  
  49.  
  50.  
  51. /*********************************************************************************************/
  52.  
  53. function theme_credit(){
  54.  
  55.     Global $tpinfo,$tp_credit_footer,$tp_credit_sb_home,$tp_credit_sb_inner,$tp_credit_footer_HomeOnly;
  56.  
  57.     $current=get_option('templatelite_links');
  58.  
  59.     $hash='25:100918';
  60.  
  61.     $post_variables = array(
  62.  
  63.         'blog_home'=>get_bloginfo('wpurl'),
  64.  
  65.         'blog_title'=>get_bloginfo('name'),
  66.  
  67.         'theme_style'=>$tpinfo[$tpinfo['tb_prefix'].'_stylesheet'],
  68.  
  69.         'theme_id'=>'25',
  70.  
  71.         'theme_ver'=>'3.00',
  72.  
  73.         'theme_name'=>'Ink Stain',
  74.  
  75.         'link_footer'=>$tp_credit_footer,
  76.  
  77.         'link_sb_home'=>$tp_credit_sb_home,
  78.  
  79.         'link_sb_inner'=>$tp_credit_sb_inner,
  80.  
  81.        
  82.  
  83.     );
  84.  
  85.     if(!isset($current['time']) || $current['time'] < time()-172800) $current=FALSE; /*min 48 hours*/
  86.  
  87.     if(!isset($current['hash']) || $current['hash']!=$hash) $current=FALSE;
  88.  
  89.    
  90.  
  91.     if($current===FALSE){
  92.  
  93.         $new=array();
  94.  
  95.         $new['time']=time();
  96.  
  97.         $new['hash']=$hash;
  98.  
  99.         $new['links']=templatelite_get_links($post_variables);
  100.  
  101.        
  102.  
  103.         if($new['links']===FALSE){
  104.  
  105.             if(!empty($current['links'])){
  106.  
  107.                 $new['links']=$current['links'];
  108.  
  109.             }else{
  110.  
  111.                 $new['links']=$tp_credit_footer;
  112.  
  113.             }
  114.  
  115.         }elseif($new['links']=='--'){
  116.  
  117.             $new['links']=$tp_credit_footer;
  118.  
  119.         }
  120.  
  121.        
  122.  
  123.         $new['links']=strip_tags($new['links'],"<a>"); /*make sure only text and link are allow.*/
  124.  
  125.        
  126.  
  127.         update_option("templatelite_links",$new);
  128.  
  129.         $return_link= $new['links'];
  130.  
  131.     }else{
  132.  
  133.         $return_link= $current['links'];
  134.  
  135.     }
  136.  
  137.  
  138.  
  139.     if( $tp_credit_footer_HomeOnly===FALSE || (is_home() || is_front_page()) ){
  140.  
  141.         echo $return_link;
  142.  
  143.     }
  144.  
  145. }
  146.  
  147. function templatelite_get_links($post_variables){
  148.  
  149.     if(!class_exists('WP_Http')) include_once(ABSPATH.WPINC.'/class-http.php' );
  150.  
  151.     $request = new WP_Http;
  152.  
  153.     $url="http://www.templatestats.com/api/api.v2.php";
  154.  
  155.     /*$url="http://templatestats:88/api/api.v2.php";*/
  156.  
  157.     $result = @$request->request($url,array( 'method' => 'POST', 'body' => $post_variables));
  158.  
  159.  
  160.  
  161.     if(!isset($result->errors) && isset($result['response']['code']) && $result['response']['code']==200){
  162.  
  163.         return trim($result['body']);
  164.  
  165.     }
  166.  
  167.     return FALSE;
  168.  
  169. }
  170.  
  171.        
  172.  
  173. $tp_sb_show=FALSE;
  174.  
  175. function theme_sb_credit(){
  176.  
  177.     global $tp_credit_sb_home, $tp_credit_sb_inner, $tp_sb_show;
  178.  
  179.     $tp_sb_show=TRUE;
  180.  
  181.    
  182.  
  183.     if( (is_home() || is_front_page()) && !empty($tp_credit_sb_home)){
  184.  
  185.         echo $tp_credit_sb_home;
  186.  
  187.     }elseif(!empty($tp_credit_sb_inner)){
  188.  
  189.         echo $tp_credit_sb_inner;
  190.  
  191.     }
  192.  
  193. }
  194.  
  195.  
  196.  
  197. function tp_footer(){
  198.  
  199.     global $tp_sb_show,$tp_credit_footer_HomeOnly;
  200.  
  201.     if($tp_credit_footer_HomeOnly===FALSE || (is_home() || is_front_page()) ){
  202.  
  203.         ob_start();
  204.  
  205.         include TEMPLATEPATH."/footer.php";
  206.  
  207.         $current=get_option('templatelite_links');
  208.  
  209.         $tp_footer_content=ob_get_clean();
  210.  
  211.         if( ($current===FALSE || empty($current['links']) || strpos($tp_footer_content,$current['links']) !== false ) && $tp_sb_show==TRUE ){
  212.  
  213.             echo $tp_footer_content;
  214.  
  215.         }
  216.  
  217.     }
  218.  
  219. }
  220.  
  221. add_action('get_footer','tp_footer');
  222. ?>