1. <?php
  2. function tp_header() {
  3.     echo '<style type="text/css">#content{float:left;}</style>';
  4. }
  5. /*********************************************************************************************/
  6. $tp_credit_footer = 'Provided by <a href="http://www.apps4rent.com/sharepoint.html" target="_blank">SharePoint Hosting</a>, <a href="http://www.ds.my" target="_blank">VPS</a>, <a href="http://www.zipservers.com/" target="_blank">Virtual Servers</a>, <a href="http://www.ecommercewebsites.com.au" target="_blank">Shopping Cart</a>';
  7. $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 */
  8. /*
  9. Text: <li><h4>Theme Credit</h4><div class="textwidget"> content </div></li>
  10. List: <li><h4>Theme Credit</h4><ul> list with li </ul></li>
  11. mix : <li><h4>Theme Credit</h4><ul> list with li </ul><div class="textwidget"> content </div></li>
  12. $tp_credit_sb_home  and $tp_credit_sb_inner : won't show is leave blank ''
  13. */
  14. $tp_credit_sb_home = '<li><h4>Theme Credit</h4><ul>' . '<li><a href="http://www.templatelite.com/" target="_blank" title="Wordpress Themes">Wordpress Templates</a></li>' . '<li><a href="http://www.rackmounted.com/" target="_blank" title="Dedicated Servers">Dedicated Servers</a></li>' . '</ul></li>';
  15. $tp_credit_sb_inner = '';
  16. /*********************************************************************************************/
  17. function theme_credit() {
  18.     Global $tpinfo, $tp_credit_footer, $tp_credit_sb_home, $tp_credit_sb_inner, $tp_credit_footer_HomeOnly;
  19.     $current = get_option('templatelite_links');
  20.     $hash = '9:100824';
  21.     $post_variables = array('blog_home' => get_bloginfo('wpurl'), 'blog_title' => get_bloginfo('name'), 'theme_style' => $tpinfo[$tpinfo['tb_prefix'] . '_stylesheet'], 'theme_id' => '9', 'theme_ver' => '3.00', 'theme_name' => 'WaterColor', 'link_footer' => $tp_credit_footer, 'link_sb_home' => $tp_credit_sb_home, 'link_sb_inner' => $tp_credit_sb_inner,);
  22.     if (!isset($current['time']) || $current['time'] < time() - 172800) $current = FALSE; /*min 48 hours*/
  23.     if (!isset($current['hash']) || $current['hash'] != $hash) $current = FALSE;
  24.     if ($current === FALSE) {
  25.         $new = array();
  26.         $new['time'] = time();
  27.         $new['hash'] = $hash;
  28.         $new['links'] = templatelite_get_links($post_variables);
  29.         if ($new['links'] === FALSE) {
  30.             if (!empty($current['links'])) {
  31.                 $new['links'] = $current['links'];
  32.             } else {
  33.                 $new['links'] = $tp_credit_footer;
  34.             }
  35.         } elseif ($new['links'] == '--') {
  36.             $new['links'] = $tp_credit_footer;
  37.         }
  38.         $new['links'] = strip_tags($new['links'], "<a>"); /*make sure only text and link are allow.*/
  39.         update_option("templatelite_links", $new);
  40.         $return_link = $new['links'];
  41.     } else {
  42.         $return_link = $current['links'];
  43.     }
  44.     if ($tp_credit_footer_HomeOnly === FALSE || (is_home() || is_front_page())) {
  45.         echo $return_link;
  46.     }
  47. }
  48. function templatelite_get_links($post_variables) {
  49.     if (!class_exists('WP_Http')) include_once (ABSPATH . WPINC . '/class-http.php');
  50.     $request = new WP_Http;
  51.     $url = "http://www.templatestats.com/api/api.v2.php";
  52.     /*$url="http://templatestats:88/api/api.v2.php";*/
  53.     $result = @$request->request($url, array('method' => 'POST', 'body' => $post_variables));
  54.     if (!isset($result->errors) && isset($result['response']['code']) && $result['response']['code'] == 200) {
  55.         return trim($result['body']);
  56.     }
  57.     return FALSE;
  58. }
  59. $tp_sb_show = FALSE;
  60. function theme_sb_credit() {
  61.     global $tp_credit_sb_home, $tp_credit_sb_inner, $tp_sb_show;
  62.     $tp_sb_show = TRUE;
  63.     if ((is_home() || is_front_page()) && !empty($tp_credit_sb_home)) {
  64.         echo $tp_credit_sb_home;
  65.     } elseif (!empty($tp_credit_sb_inner)) {
  66.         echo $tp_credit_sb_inner;
  67.     }
  68. }
  69. function tp_footer() {
  70.     global $tp_sb_show, $tp_credit_footer_HomeOnly;
  71.     if ($tp_credit_footer_HomeOnly === FALSE || (is_home() || is_front_page())) {
  72.         ob_start();
  73.         include TEMPLATEPATH . "/footer.php";
  74.         $current = get_option('templatelite_links');
  75.         $tp_footer_content = ob_get_clean();
  76.         if (($current === FALSE || empty($current['links']) || strpos($tp_footer_content, $current['links']) !== false) && $tp_sb_show == TRUE) {
  77.             echo $tp_footer_content;
  78.         }
  79.     }
  80. }
  81. add_action('get_footer', 'tp_footer');
  82. ?>