2014-02-10 45 views
-1

後,我搬到我的網站到其他服務器,我得到這個消息對我的wordpress調試器:#Solved - 移動網站後:意外(T_VARIABLE),預計功能(T_FUNCTION)

Parse error: syntax error, unexpected '$plg' (T_VARIABLE), expecting function (T_FUNCTION) in /var/www/pls.de/wp-content/plugins/pls-checklist/pls_checklist.php on line 469

線469僅僅是這一個(它的代碼的最後一行)$ PLG =新Agile_Checklist();

我想我的新的服務器有PHP的新版本是什麼讓這個錯誤,但我該如何解決這一問題?

以下是文件:

<?php 


if (!class_exists('Agile_Checklist')){ 
class Agile_Checklist{ 

    function __construct() { 
     add_action('admin_init', array(&$this, 'admin_init')); 
     add_action('init', array(&$this, 'fe_init')); 
     add_action('admin_menu', array(&$this, 'addAdminPage')); 
     add_action('admin_enqueue_scripts', array(&$this, 'scripts_method')); 
     add_action('wp_enqueue_scripts', array(&$this, 'frontend_scripts')); 
     add_action('admin_footer', array(&$this, 'admin_footer')); 
     add_shortcode('agile_checklist', array(&$this, 'checklist_page')); 
     add_shortcode('agile_return', array(&$this, 'return_page')); 
     add_shortcode('agile_cl_overall', array(&$this, 'overall_page')); 
     register_activation_hook(__FILE__, array($this, 'install')); 
     //register_deactivation_hook(__FILE__, array($this, 'de_activate')); 
    } 

    function fe_init(){ 
     ob_start(); 
    } 
    function admin_init(){ 
     /* Register our stylesheet. */ 
     wp_register_style('checklist_admin_style', plugins_url('css/admin.css', __FILE__)); 
     if (!session_id()) { 
      session_start(); 
     } 
     ob_start(); //holds output till full page is loaded 
    } 
    function addAdminPage() { 
     add_menu_page('Checklist', 'Checklist', 'manage_options', 'agile_checklist', array(&$this, 'view_lists')); 
     add_submenu_page('', 'Edit Checklist', 'Edit Checklist', 'manage_options', 'agile_edit_checklist', array(&$this, 'edit_list')); 
    } 
    function scripts_method(){ 
     wp_enqueue_script('jquery'); 
     wp_enqueue_script('checklist_admin', plugins_url('js/admin.js', __FILE__)); 
     wp_enqueue_style('checklist_admin_style'); 
    } 
    function frontend_scripts(){ 
     wp_enqueue_script('jquery'); 
     wp_enqueue_script('stc-front', 
      plugins_url('js/front.js', __FILE__) 
     ); 
     wp_enqueue_style('checklist_front_style', plugins_url('css/front.css', __FILE__)); 
    } 
    function admin_footer() { 

    } 
    function view_lists(){ 
     if(isset($_POST['submit'])){ 
      if($_POST['submit']=='Del'){ 
       $this->del_checklist($_POST['list_name']); 
       $msg="Checklist Deleted"; 
      } 
      if($_POST['submit']=='Add'){ 
       $name=$_POST['list_name']; 
       if($this->checklist_exists($name)){ 
        $msg="Checklist already exists"; 
       }else{ 
        wp_redirect(admin_url()."admin.php?page=agile_edit_checklist&name={$name}"); 
        exit; 
       } 
      } 
     } 
     ?> 
      <div><h1>Manage Checklists</h1></div> 
      <div id="msg"><?php echo $msg;?></div> 
      <div id="div_add_new"><button id="btn_add_new" type="button" name="" value="" class="button-primary">Add New</button></div> 
      <div id="add_new"> 
       <form name="frm_add_new" method="post" action=""> 
        <label for="list_name">List Name</label> 
        <input type="text" name="list_name" id="list_name"> 
        <input type="submit" name="submit" value="Add" class="button-primary"> 
       </form> 
      </div> 
      <div id="cl_row"> 
       <div class="cl_list_name"><h3>Checklist Name</h3></div> 
       <div class="cl_list_questions"><h3>Questions</h3></div> 
      </div> 
     <?php 
      $rs = $this->get_checklists(); 
      if($rs){ 
        foreach($rs as $r){ 
     ?> 
        <div class="cl_row"> 
         <form name="cl_list" method="post" action=""> 
          <div class="cl_list_name"><a href="<?php echo admin_url()."admin.php?page=agile_edit_checklist&name={$r->name}";?>"><?php echo $r->name?></a></div> 
          <div class="cl_list_questions"><?php echo $r->questions;?></div> 
          <input type="hidden" name="list_name" value="<?php echo $r->name?>"> 
          <div class="edit_del"><input type="submit" name="submit" value="Del" class="button-primary" onClick="return confirm('Are you sure to delete checklist?');"> </div> 
         </form> 
        </div> 
     <? 
        } //foreach ends 
      } //if rs ends 
    } 
    function edit_list(){ 
     if(isset($_POST['submit'])){ 
      if($_POST['submit']=='Del'){ 
       $this->del_question($_POST['edit_id']); 
       $msg="Question Deleted"; 
      } 
      if($_POST['submit']=='Add'){ 
       if($this->question_exists($_POST['edit_question'])){ 
        $msg="Question already exists"; 
       }else{ 
        $this->save_question($_POST); 
        $msg="Question Saved"; 
       } 
      } 
      if($_POST['submit']=='Save'){ 
       $this->update_question($_POST); 
       $msg="Question updated"; 
      } 
     } 
     $name=$_GET['name']; 
     if(empty($name)) return; 
     $new = isset($_GET['new']); 
     if($new){ 
      if($this->checklist_exists($name)){ 
       echo "{$name} already exists, Select a different name"; 
       return; 
      } 
     } 
     ?> 
     <div><h1>Edit Checklist <?php echo $name;?></h1></div> 
     <div id="msg"><?php echo $msg;?></div> 
     <div id="div_add_new"><button id="btn_add_new" type="button" name="" value="" class="button-primary">Add New</button></div> 
      <div id="add_new"> 
       <form name="frm_add_new" method="post" action=""> 
        <label for="edit_question">Question</label> 
        <input id="btn_add_new_question" type="text" name="edit_question" size="60"> 
        <label for="edit_marks">Marks</label> 
        <input id="btn_add_new_marks" type="text" name="edit_marks" size="4"> 
        <input type="hidden" name="edit_name" value="<?php echo $name?>"> 
        <input id="btn_add_new_submit" type="submit" name="submit" value="Add" class="button-primary"> 
       </form> 
      </div> 
      <div class="edit_row"> 
       <div class="edit_question"><h3>Question</h3> </div> 
       <div class="edit_marks"><h3>Marks</h3> </div> 
      </div> 

     <?php 
      $rs = $this->get_questions($name); 
      foreach($rs as $r){ 
     ?> 
      <form name="frm_add_new" method="post" action=""> 
      <div class="edit_row"> 
       <div class="edit_question"><input type="text" name="edit_question" size="60" value="<?php echo $r->question;?>"> </div> 
       <div class="edit_marks"><input type="text" name="edit_marks" size="4" value="<?php echo $r->marks;?>"> </div> 
       <input type="hidden" name="edit_id" value="<?php echo $r->id?>"> 
       <div class="edit_del"><input type="submit" name="submit" value="Del" class="button-primary" onClick="return confirm('Are you sure to delete question?');"> </div> 
       <div class="edit_save"><input type="submit" name="submit" value="Save" class="button-primary"></div> 
      </div> 
      </form> 
     <?php 
      } //foreach ends 
    } 
    function overall_page($atts, $content = null){ 
     wp_enqueue_style('agile_cl_checklist_fe', plugins_url('css/front.css', __FILE__)); 

     //get current user info 
     global $current_user; 
     get_currentuserinfo(); 
     $userid = $current_user->ID; 

     $overall = $this->get_overall_percent($userid); 
     $ret = ' 
       <progress class="bar" max="100" value="'.$overall.'"> 
        <strong>HTML5 not supported on this browser</strong> 
       </progress> 
       '; 
     return $ret; 
    } 
    function return_page($atts, $content = null){ 
     wp_enqueue_style('agile_cl_checklist_fe', plugins_url('css/front.css', __FILE__)); 
     extract(shortcode_atts(array(
      'url' => site_url(), 
      'score' => 0, 
     ), $atts) 
     ); 

     //get current user info 
     global $current_user; 
     get_currentuserinfo(); 
     $userid = $current_user->ID; 

     $overall = $this->get_overall_percent($userid); 
     if($overall < $score){ 
      wp_redirect($url); 
      exit; 
     } 
    } 
    function checklist_page($atts, $content = null){ 
     wp_enqueue_style('agile_cl_checklist_fe', plugins_url('css/front.css', __FILE__)); 
     extract(shortcode_atts(array(
      'name' => "test", 
     ), $atts) 
     ); 

     //get current user info 
     global $current_user; 
     get_currentuserinfo(); 
     $userid = $current_user->ID; 

     //handle post 
     if(isset($_POST['submit'])){ 
      $aids = $_POST['aid']; 
      $mks = $_POST['marksobtained']; 
      $n=0; 

      foreach($aids as $aid){ 
       $this->update_aid($aid,$mks[$n]); 
       $n++; 
      } 
     } 

     //setup answers 
     $this->setup_answers($name,$userid); 

     $rs = $this->get_question_answers($name,$userid); 
     if($rs){ 
       $per = $this->get_checklist_percent($name,$userid); 
       $overall = $this->get_overall_percent($userid); 
       $tot = $this->get_checklist_total($name); 

       $op=' 
       <form name="frm_checklist" method="post" action=""> 
        <div id="checklist_wrap"> 
         <div class="cl_fe_row"><div class="bar_title">Fortschritt:</div> 
          <progress id="pbar" class="bar" max="100" value="'.$per.'"> 
           <strong>HTML5 not supported on this browser</strong> 
          </progress> 
         </div> 
         <input id="tot" type="hidden" name="tot" value="'.$tot.'"> 
       '; 
         foreach($rs as $r){ 
         if($r->marksobtained == 0){ 
          $icon='no.jpg'; 
         }else{ 
          $icon='yes.jpg'; 
         } 
       $op .=' 
          <div class="cl_fe_row"> 
           <div class="cl_icon"><img class="cl_img" id="img_'.$r->aid.'" src="'. plugins_url('img/', __FILE__).$icon.'" height="32" width="32"> </div> 
           <div class="cl_question">'.$r->question.'</div> 
           <input id="mko_'.$r->aid.'" type="hidden" name="marksobtained[]" value="'.$r->marksobtained.'"> 
           <input id="mkt_'.$r->aid.'"type="hidden" name="marks[]" value="'. $r->marks.'"> 
           <input type="hidden" name="aid[]" value="'.$r->aid.'"> 
          </div> 
        ';//op2 
         } //foreach ends 
       $op .=' 
         <div class="cl_fe_row"><input type="submit" name="submit" value="Speichern" class="css3button"></div> 

        </div> 
       </form> 
       '; //op3 
     } //if rs ends 
     return $op; 
    } 
    function install(){ 
     global $wpdb; 
     require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
     $sql=" 
      CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."agile_checklist_answers` (
       `id` int(11) NOT NULL AUTO_INCREMENT, 
       `userid` int(11) NOT NULL, 
       `listname` varchar(30) NOT NULL, 
       `qid` int(11) NOT NULL, 
       `marksobtained` int(11) NOT NULL, 
       PRIMARY KEY (`id`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 
      "; 
     dbDelta($sql); 
     $sql=" 
      CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."agile_checklist_questions` (
       `id` int(11) NOT NULL AUTO_INCREMENT, 
       `name` varchar(30) NOT NULL, 
       `question` varchar(255) NOT NULL, 
       `marks` int(11) NOT NULL, 
       PRIMARY KEY (`id`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 
      "; 
     dbDelta($sql); 
     /* 
     $sql=" 
      CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."agile_checklist_totals` (
       `id` int(11) NOT NULL AUTO_INCREMENT, 
       `userid` int(11) NOT NULL, 
       `listname` varchar(30) NOT NULL, 
       `total` int(11) NOT NULL, 
       PRIMARY KEY (`id`) 
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; 
      "; 
     dbDelta($sql); 
     */ 
    } 
    function setup_answers($name,$userid){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql="Select * from {$wpdb->prefix}agile_checklist_answers where listname='{$name}' and userid={$userid}"; 
     $rsa = $wpdb->get_results($sql); 
     $rsq = $this->get_questions($name); 
     if(count($rsa) == count($rsq)) return; 

     $sql = "delete from {$wpdb->prefix}agile_checklist_answers where listname='{$name}' and userid={$userid}"; 
     $wpdb->query($sql); //delete any un sync answers 

     foreach($rsq as $r){ 
      $sql = "insert into {$wpdb->prefix}agile_checklist_answers (userid,listname,qid,marksobtained) values({$userid},'{$name}',{$r->id},0)"; 
      $wpdb->query($sql); 
     } 
    } 
    function get_questions($name){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql="Select * from {$wpdb->prefix}agile_checklist_questions where name='{$name}'"; 
     $rs = $wpdb->get_results($sql); 
     return $rs; 
    } 
    function update_aid($aid,$marksobtained){ 
     global $wpdb; 

     $sql="update {$wpdb->prefix}agile_checklist_answers set marksobtained={$marksobtained} where id='{$aid}'"; 
     $wpdb->query($sql); 
    } 
    function del_question($id){ 
     global $wpdb; 

     $sql="Delete from {$wpdb->prefix}agile_checklist_questions where id='{$id}'"; 
     $wpdb->query($sql); 
    } 
    function del_checklist($name){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql="Delete from {$wpdb->prefix}agile_checklist_questions where name='{$name}'"; 
     $wpdb->query($sql); 
    } 
    function save_question($p){ 
     global $wpdb; 

     $name=strtolower($p['edit_name']); 
     $question=$p['edit_question']; 
     $marks=$p['edit_marks']; 
     $sql="Insert into {$wpdb->prefix}agile_checklist_questions (name,question,marks) values('{$name}','{$question}',{$marks})"; 
     $wpdb->query($sql); 
    } 
    function update_question($p){ 
     global $wpdb; 

     $id=$p['edit_id']; 
     $question=$p['edit_question']; 
     $marks=$p['edit_marks']; 
     $sql="update {$wpdb->prefix}agile_checklist_questions set question='{$question}', marks={$marks} where id={$id}"; 
     $wpdb->query($sql); 
    } 
    function question_exists($q){ 
     global $wpdb; 

     $sql="Select * from {$wpdb->prefix}agile_checklist_questions where question='{$q}'"; 
     $rs = $wpdb->get_results($sql); 
     if($rs) return true; 
     return false; 
    } 

    function get_checklists(){ 
     global $wpdb; 

     $sql="Select name, count(question) as questions from {$wpdb->prefix}agile_checklist_questions GROUP BY name order by name"; 
     $rs = $wpdb->get_results($sql); 
     return $rs; 
    } 
    function get_checklist($name){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql="Select * from {$wpdb->prefix}agile_checklist_questions where name='{$name}'"; 
     $rs = $wpdb->get_results($sql); 
     return $rs; 
    } 
    function get_question_answers($name,$userid){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql=" 
      SELECT q . * , a.id AS aid, a.marksobtained 
      FROM {$wpdb->prefix}agile_checklist_questions AS q, {$wpdb->prefix}agile_checklist_answers AS a 
      WHERE q.id = a.qid 
      AND q.name = '{$name}' 
      AND a.userid ={$userid} 
      "; 
     $rs = $wpdb->get_results($sql); 
     return $rs; 
    } 
    function get_checklist_total($name){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql=" 
       SELECT (
       sum(marks) 
       ) AS p 
       FROM {$wpdb->prefix}agile_checklist_questions where name = '{$name}' 
      "; 
     $rs = $wpdb->get_var($sql); 
     return $rs; 
    } 
    function get_checklist_percent($name,$userid){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql=" 
       SELECT (
       sum(a.marksobtained)/sum(marks) *100 
       ) AS p 
       FROM {$wpdb->prefix}agile_checklist_questions AS q, {$wpdb->prefix}agile_checklist_answers AS a 
       WHERE q.id = a.qid 
       AND q.name = '{$name}' 
       AND a.userid ={$userid} 
      "; 
     $rs = $wpdb->get_var($sql); 
     return $rs; 
    } 
    function get_overall_percent($userid){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql=" 
       SELECT (
       sum(marksobtained) 
       ) AS p 
       FROM {$wpdb->prefix}agile_checklist_answers AS a 
       WHERE userid ={$userid} 
      "; 
     $mo = $wpdb->get_var($sql); 
     $sql= "Select sum(marks) from {$wpdb->prefix}agile_checklist_questions"; 
     $mt = $wpdb->get_var($sql); 

     return ($mo/$mt *100); 
    } 
    function checklist_exists($name){ 
     global $wpdb; 

     $name=strtolower($name); 
     $sql="Select * from {$wpdb->prefix}agile_checklist_questions where 
name='{$name}'"; 
     $rs = $wpdb->get_results($sql); 
     if($rs) return true; 
     return false; 
    } 


} //class ends 
} //class exists ends 
$plg = new Agile_Checklist(); 
?> 

回答

1

你在這個新的服務器使用PHP的短標記<?也許不可 所以儘量將其更改爲長標籤<?php,看看發生 或者你有你的服務器(S)的訪問打開在php.ini 復位的Apache和急短標籤!看看會發生什麼。

0

嘗試聲明類以上,你的條件或嘗試在一個單獨的文件$plg = new Agile_Checklist();

require ('AgileChecklist.php'); $plg = new Agile_Checklist();

0

感謝您的竅門,以創建一個新的實例! 我已經看到他們到晚期,所以我降級到PHP 5.3,現在它的工作原理也。

三江源,稍後會嘗試這種在TESTSERVER,也許再次升級PHP。