2014-10-10 110 views
0

我在这段代码的最后一行出现意外的文件错误结束,我已经通过www.phpcodechecker.com(我发现它非常可靠)运行它。我究竟做错了什么? PHP版本5.5.9PHP意外的文件结尾

<?php 
/* 
    Hurricane Control Panel © 2014, a web control panel 
    by Hurricane Development of http://www.HurricaneDevelopment.com 
    is licenced under a Creative Commons 
    Attribution-NoDerivatives 4.0 International License 
    Permissions beyond the scope of this licence 
    may be available at http://creativecommons.org/licenses/by-nd/4.0/ 
*/ 

Defined("_HEXEC") or die ("This file may not be accessed directly"); 

class VARS { 
    public static $errors = false; 
    public static $extraJS = false; 
    public static $scriptJS = false; 
    public static $extraCSS = false; 
} 

abstract class GeneralUTIL { 
    /** 
    * Error functions 
    **/ 
    public static function addErr($err) { 
    VARS::$errors[] = $err; 
    } 

    public static function logger($content,$level = LOGGER_INFO) { 
    if (!file_exists("logs")) { 
     mkdir("logs"); 
    } 

    $scanned_directory = array_diff(scandir("logs",SCANDIR_SORT_DESCENDING), array('..', '.')); 
    $logs = false; 

    if (sizeof($scanned_directory) == 0) { 
     file_put_contents("logs/log.1", "", LOCK_EX); 
     chmod("logs/log.1",0600); 
     $logid = 1; 
    } else { 
     foreach ($scanned_directory as $key => $value) { 
     if (strpos($value,"log.") !== false) { 
      $logs[] = $value; 
     } 
     } 

     $logid = explode(".", $logs[0]); 
     $logid = $logid[1]; 

     if (filesize("logs/log." . $logid) >= 200000) { 
     $logid = ((int) $logid) + 1; 
     file_put_contents("logs/log." . $logid, "", LOCK_EX); 
     chmod("logs/log." . $logid,0600); 
     } 
    } 


    date_default_timezone_set("America/New_York"); 
    $d = getdate(); 

    file_put_contents("logs/log." . $logid, "{$d['mon']}/{$d['mday']}/{$d['year']} {$d['hours']}:{$d['minutes']}:{$d['seconds']} $level $content \n", FILE_APPEND | LOCK_EX); 
    } 

    public static function sha512($password,$salt = null) { 
    if ($salt == null) { 
     $cost = 50000; 

     $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.'); 

     $salt = sprintf('$6$rounds=%d$', $cost) . $salt; 
    } 

    return crypt($password, $salt); 
    } 

    public static function matchSha512($password,$hash) { 
    if (crypt($password, $hash) === $hash) { 
     return true; 
    } 
    return false; 
    } 
} 

class PluginUTIL extends GeneralUTIL { 

    public static function addJS($jsPath) { 
    $debugArray = debug_backtrace(); 
    $pluginAlias = UTIL::getBetween($debugArray[0]['file'],"/plugins/plugin_","/"); 

    if ($pluginAlias == false) { 
     UTIL::addErr("The addJS Method was not called from a registered plugin"); 
     return false; 
    } 

    $pluginLoader = new Plugins(); 

    $pluginLoader->loadPlugins(); 
    $plugins = $pluginLoader->getPluginsArray(); 

    foreach ($plugins as $id => $pluginArray) { 
     if ($pluginArray['alias'] == $pluginAlias) { 
     VARS::$extraJS[] = PATH . "plugins/plugin_" . $pluginAlias . "/" . $jsPath; 

     return true; 
     } 
    } 
    } 

    public static function addScriptJS($script) { 
    VARS::$scriptJS = $script; 
    } 

    public static function addCSS($cssPath) { 
    $debugArray = debug_backtrace(); 
    $pluginAlias = UTIL::getBetween($debugArray[0]['file'],"/plugins/plugin_","/"); 

    if ($pluginAlias == false) { 
     UTIL::addErr("The addCSS Method was not called from a registered plugin"); 
     return false; 
    } 

    $pluginLoader = new Plugins(); 

    $pluginLoader->loadPlugins(); 
    $plugins = $pluginLoader->getPluginsArray(); 

    foreach ($plugins as $id => $pluginArray) { 
     if ($pluginArray['alias'] == $pluginAlias) { 
     VARS::$extraCSS[] = PATH . "plugins/plugin_" . $pluginAlias . "/" . $cssPath; 

     return true; 
     } 
    } 
    } 

} 

class UTIL extends GeneralUTIL { 

    public static function displayErrors($output) { 
     if (VARS::$errors != false && is_array(VARS::$errors)) { 
     $output = str_replace("<div id='errors' class='alert alert-danger'></div>","<div id='errors' class='alert alert-danger'><h1>Uh Oh. Some errors occured!</h1>" . implode("<br>",VARS::$errors) . "</div>",$output); 
     } else { 
     $output = str_replace("<div id='errors' class='alert alert-danger'></div>","",$output); 
     } 
     return $output; 
    } 

    /** 
    * Custom JS /CSS functions 
    **/ 
    public static function addCustomJSFromPath($path) { 
    VARS::$extraJS[] = PATH . $path; 
    } 

    public static function includeCustomJS() { 
     if (VARS::$extraJS != false && is_array(VARS::$extraJS)) { 
     foreach (VARS::$extraJS as $key => $path): ?> 
      <script src="<?php echo $path; ?>"></script> 
     <?php endforeach; 
     } 

     if (VARS::$scriptJS != false): ?> 
     <script type="text/javascript"> 
      <?php echo VARS::$scriptJS; ?> 
     </script> 
     <? endif; 
    } 

    public static function includeCustomCSS($output) { 
     if (VARS::$extraCSS != false && is_array(VARS::$extraCSS)) { 
     $css = ""; 

     foreach (VARS::$extraCSS as $key => $path): 
      $css .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$path\">\n"; 
     endforeach; 

     $output = str_replace("CUSTOMCSSAREAHERE",$css,$output); 
     } else { 
     $output = str_replace("CUSTOMCSSAREAHERE","",$output); 
     } 

     return $output; 
    } 

    /** 
    * Get Between two strings function 
    **/ 
    public static function getBetween($content,$start,$end) { 
    if (preg_match('/' . str_replace("/","\\/", $start) . '(.*?)' . str_replace("/","\\/", $end) . '/',$content, $res) === false) { 
     return false; 
    } 
    return $res[1]; 
    } 

    /** 
    * Redirect page function 
    **/ 
    public static function redirect($location, $code = '302') { 
    switch($code) { 
     case '301'; 
     header("HTTP/1.1 301 Moved Permanently"); 
     break; 
     case '303'; 
     header("HTTP/1.1 303 See Other"); 
     break; 
     case '404'; 
     header('HTTP/1.1 404 Not Found'); 
     break; 
    } 
    //remove any &amp; in the url to prevent any problems 
    $location = str_replace('&amp;', '&', $location); 
    header("Location: $location"); 
    //kill the script from running and output a link for browsers which enable turning off header redirects *cough Opera cough* :P 
    exit('<a href="'.$location.'">If you were not redirected automatically please click here</a>'); 
    } 
} 

?> 
+0

您是否尝试过丢弃收盘'?>',使最后一行文件'}'的文件? – slapyo 2014-10-10 23:33:44

回答

5

更改此

<? endif; 

这个

<?php endif; 

UTIL::includeCustomJS

+2

rogelio在平局上是速度最快的;) – 2014-10-10 23:37:28

+0

你是有史以来最伟大的人 – 2014-10-10 23:39:18

+0

这是一个超级巨型超级冒险者已知的错误。 – rogelio 2014-10-10 23:40:14