2014-03-06 16 views
0

我想安裝一箇舊的插件(我不知道最聰明的想法)。但是,試圖激活我得到以下插件無法啓動,因爲它觸發了一個致命的錯誤

解析錯誤錯誤的插件時:語法錯誤,意想不到的$結束/public_html/site/wp-content/plugins/kofthitscounter/wp-KOFThitscounter.php線167

該插件兼容WP版本3.5.2,我們在3.8上,所以我認爲它可能需要重新編寫腳本。

這裏是該文件

<script type="text/javascript"> 
    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-38371699-1']); 
    _gaq.push(['_trackPageview']); 
    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 
</script> 
<?php 
/* 
Plugin Name: KOFT Hits Counter 
Author URI: http://www.Knowledgeonfingertips.com 
Description: KOFT Post Hits Counter displays the number of hits/views on each of page or post. A simple count indicates how many times a page has been accessed or opened. 
Version: 1.5 
Author: Knowledgeonfingertips.com 
Author URI: http://www.Knowledgeonfingertips.com 
*/ 
global $wpdb; 
define('HC_TABLE_NAME', $wpdb->prefix . 'KOFT_hitcount'); 
define('HC_PATH', ABSPATH . 'wp-content/plugins/KOFThitcounter'); 
require_once(ABSPATH . '/wp-includes/pluggable.php'); 
$themename = "KOFTMenu"; 
$shortname = "KM"; 
$position = '63.3'; 
$icon = $file_dir."/images/koft.png"; 
// Hook for adding admin menus 
add_action('admin_menu', 'mt_add_pages'); 
// action function for above hook 
function mt_add_pages() { 
    # add submenu 
    $mincap=get_option('KOFT_mincap'); 
    if($mincap == '') { 
    $mincap="level_2"; 
    } 
    add_menu_page('KOFT Admin', 'KOFT Admin', $mincap, __FILE__, 'iniKOFT', plugins_url('KOFThitscounter/images/KOFT.png',dirname(plugin_basename(__FILE__)))); 
    add_submenu_page(__FILE__, __('Check Hits','KOFT'), __('Check Hits','KOFT'), $mincap, __FILE__ . '&KOFT_action=overview', 'iniKOFT'); 
    add_submenu_page(__FILE__, __('Visit Website','KOFT'), __('Visit Website','KOFT'), $mincap, __FILE__ . '&KOFT_action=redirect', 'iniKOFT'); 
} 
function iniKOFT() 
{ 
    if(isset($_GET['KOFT_action'])) 
    { 
     if ($_GET['KOFT_action'] == 'redirect') 
     { 
      iniKOFTRedirect();  
     } 
     elseif ($_GET['KOFT_action'] == 'overview') 
     { 
      iniKOFTMain(); 
     } 
    }else iniKOFTMain(); 
} 
function iniKOFTRedirect() { 
    echo "<script language=javascript>window.location.href= 'http://www.knowledgeonfingertips.com'</script>"; 
} 
/** 
* Show overwiew 
*/ 
function iniKOFTMain() 
{ 
    global $wpdb; 
    $table_name = $wpdb->prefix . "KOFT_hitcount"; 
    $querylimit="LIMIT 50"; 
    # Tabella Last hits 
    "<div class='wrap'><h2>". __('Top Page Hits','KOFT'). "</h2><table class='widefat'><thead><tr><th colspan='2' scope='col'><script type="text/javascript"><!-- 
google_ad_client = "ca-pub-3100332509000145"; 
/* KOFT ads on WP */ 
google_ad_slot = "3185802680"; 
google_ad_width = 728; 
google_ad_height = 90; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script></th></tr><tr><th scope='col'>". __('Page Url','KOFT'). "</th><th scope='col'>". __('Hit Count','KOFT'). "</th></tr></thead>"; 
    print "<tbody id='the-list'>";  

    $KOFTdrafts = $wpdb->get_results("SELECT * FROM $table_name ORDER bY hit DESC $querylimit"); 
    foreach ($KOFTdrafts as $KOFTdrafts) 
    { 
    print "<tr>"; 
    print "<td>". $KOFTdrafts->name ."</td>"; 
    print "<td>". $KOFTdrafts->hit ."</td>"; 
    print "</tr>"; 
    } 
    print "</table></div>"; 
} 
function KOFThitcounter_install(){ 
global $wpdb; 
if ($wpdb->get_var('SHOW TABLES LIKE "' . HC_TABLE_NAME . '"') != HC_TABLE_NAME) 
{ 
$sql = "CREATE TABLE IF NOT EXISTS `". HC_TABLE_NAME . "` ("; 
$sql .= "`SN` BIGINT NOT NULL AUTO_INCREMENT,"; 
$sql .= "`name` VARCHAR(1000) NOT NULL,"; 
$sql .= "`hit` BIGINT NOT NULL DEFAULT '1',"; 
$sql .= "PRIMARY KEY (`SN`)"; 
$sql .= ") ENGINE = MYISAM;"; 
$wpdb->query($sql); 
} 
} 
function KOFThitcounter_uninstall(){ 
global $wpdb; 
$sql = "DROP TABLE `". HC_TABLE_NAME . "`;"; 
$wpdb->query($sql); 
} 
register_activation_hook(__FILE__, 'KOFThitcounter_install'); 
register_deactivation_hook(__FILE__, 'KOFThitcounter_uninstall');?> 
<?php 
function KOFThitcounter_curPageURL() { 
$pageURL = 'http'; 
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} 
$pageURL .= "://"; 
if ($_SERVER["SERVER_PORT"] != "80") { 
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
} else { 
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
} 
return $pageURL; 
} 
function get_KOFThitcounter(){ 
$url = KOFThitcounter_curPageURL(); 
    $url = str_replace ("http://",'',$url); 
    $url = str_replace ("www.",'',$url); 
    if ($url != "") 
     { 
      $query = "Select hit from `". HC_TABLE_NAME . "` where name = '$url'"; 
      $result = mysql_query($query); 
      if (!$result) 
      { 
       die('Invalid query: ' . mysql_error()); 
      } 
      if (mysql_affected_rows()==0) 
      { 
       $query = "Insert into `". HC_TABLE_NAME . "` (name) values ('$url')"; 
       $result = mysql_query($query); 
       echo " Total Views: 1 "; 
       if (!$result) 
       { 
        die('Invalid query: ' . mysql_error()); 
       } 
      } 
      else 
      { 
       $hitcount = mysql_result($result, 0); 
       $hitcount++; 
       echo " Total Views: $hitcount "; 
       $query = "Update `". HC_TABLE_NAME . "` set hit = $hitcount where name = '$url'"; 
       $result = mysql_query($query); 
       if (!$result) 
       { 
        die('Invalid query: ' . mysql_error()); 
       } 
      } 
     }?> 
<?php } 
//admin setting 
add_action('admin_menu', 'KOFThitcounter_menu'); 
function KOFThitcounter_menu() { 
add_options_page('Plugin KOFThitcounter', 'KOFThitcounter Options', 1, 'plugin_KOFThitcounter_menu', 'KOFThitcounter_options'); 
} 
function KOFThitcounter_options() { 
if (!current_user_can(1)) { 
wp_die(__('You do not have sufficient permissions to access this page.')); 
} 
echo ' 
<div class="wrap">'; 
echo '<h3>Enable KOFT Hits Counter</h3>'; 
echo 'Just insert the following shortcode anywhere in your blog (for use in a widget: use the text-widget and insert the shortcode there) <br/>'; 
echo '<pre>&lt;?php get_KOFThitcounter();?&gt;</pre>'; 
} 
?> 

回答

0

代碼打擊這個錯誤意味着PHP已完成分析你的代碼,但你忘了在你的頁面或在那些被列入某處關閉的象徵。

情況:

  • 你忘了關閉報價,那麼PHP將繼續,直到找到右引號來分析你的代碼。
  • 您忘記關閉括號,因此從上次打開開始,PHP會將所有 所遵循的代碼視爲永不結束的塊的一部分。
  • 您忘了關閉括號,所以從最後一個左括號開始,PHP會將所有後續代碼視爲特定塊(條件,函數參數等)的一部分,但不會結束。
  • 您忘記了一個逗號,因此對於PHP而言,您的代碼中有一條指令沒有結束。

這意味着問題可能不在錯誤消息中提到的行上,因爲缺少的符號可能位於該點之後(或之前)的任何位置。

所以你的問題在function iniKOFTMain()
替換此...

"<div class='wrap'><h2>". __('Top Page Hits','KOFT'). "</h2><table class='widefat'><thead><tr><th colspan='2' scope='col'> 

這... ...

echo "<div class='wrap'><h2>". __('Top Page Hits','KOFT'). "</h2><table class='widefat'><thead><tr><th colspan='2' scope='col'>"?> 

這...

</th></tr><tr><th scope='col'>". __('Page Url','KOFT'). "</th><th scope='col'>". __('Hit Count','KOFT'). "</th></tr></thead>"; 

這... ...

<?php echo"</th></tr><tr><th scope='col'>". __('Page Url','KOFT'). "</th><th scope='col'>". __('Hit Count','KOFT'). "</th></tr></thead>"; 
相關問題