很多年前,互联网上还有着大量的独立博客或微博,分享些技术或者生活故事。大概是2015年开始,移动互联网发展速度有了质的飞跃,这些独立博客也就逐渐淡出了人们的视野。而当年那些风靡全球的开源博客程序,也在逐渐停止更新。
PageCookery是当年比较成熟的一款微博程序了,在还是PHP5的时代,也算是一款佳作了。不过它的更新停在了0.9.9版本。最近想在本地服务器上搭建起来怀怀旧,却发现在今天的PHP7上各种报错。于是开始了下面的改造工程。
先直接访问index.php试试。
放弃了,全是报错,一条一条改吧。
Warning: Use of undefined constant DATABASE_HOST - assumed 'DATABASE_HOST' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 12
Warning: Use of undefined constant DATABASE_USER - assumed 'DATABASE_USER' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 16
Warning: Use of undefined constant DATABASE_PSSWORD - assumed 'DATABASE_PSSWORD' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 20
Warning: Use of undefined constant DATABASE_DB_NAME - assumed 'DATABASE_DB_NAME' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 24
Warning: Use of undefined constant SITE_NAME - assumed 'SITE_NAME' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 32
Warning: Use of undefined constant BASE_URL - assumed 'BASE_URL' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 36
Warning: Use of undefined constant COOKERY_FRAMEWORK_DIR - assumed 'COOKERY_FRAMEWORK_DIR' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 44
Warning: Use of undefined constant DEBUG - assumed 'DEBUG' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 46
Warning: Use of undefined constant COOKIE_PREFIX - assumed 'COOKIE_PREFIX' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.php on line 48
Warning: Use of undefined constant WP_ENABLED - assumed 'WP_ENABLED' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.wordpress.php on line 2
Warning: Use of undefined constant WP_URL - assumed 'WP_URL' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.wordpress.php on line 3
Warning: Use of undefined constant WP_USERNAME - assumed 'WP_USERNAME' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.wordpress.php on line 4
Warning: Use of undefined constant WP_PASSWORD - assumed 'WP_PASSWORD' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.wordpress.php on line 5
Warning: Use of undefined constant WP_CATEGORY_ID - assumed 'WP_CATEGORY_ID' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.wordpress.php on line 6
Warning: Use of undefined constant PG_LANG - assumed 'PG_LANG' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\config.language.php on line 2
Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in D:\xampp\htdocs\PC\init.php on line 61
Fatal error: 'continue' not in the 'loop' or 'switch' context in D:\xampp\htdocs\PC\framework\CI\database\DB.php on line 61
Use of undefined constant ,这句大家比较熟悉,旧版本定义常量可以不加引号的,补充上就解决了。例如对config.php里面的define进行修改,原代码如下:(请注意PC需要手动修改config里面的mysql数据库信息,请一并修改)
// 数据库主机
// Database host
define(DATABASE_HOST, 'localhost');
// 数据库用户名
// Database username
define(DATABASE_USER, 'root');
// 数据库密码
// Database password
define(DATABASE_PSSWORD, 'root');
// 数据库名称
// Database name
define(DATABASE_DB_NAME, 'microblog');
############ 站点配置 ############
############ WEBSITE SETTINGS ############
// 网站名称
// Website name
define(SITE_NAME, 'PageCookery Microblog');
// 微博访问路径, 请以 / 结尾
// Website visit URL, End up with /
define(BASE_URL, 'http://127.0.0.1/microblog/');
修改后如下:
// 数据库主机
// Database host
define("DATABASE_HOST", 'localhost');
// 数据库用户名
// Database username
define("DATABASE_USER", 'root');
// 数据库密码
// Database password
define("DATABASE_PSSWORD", '');
// 数据库名称
// Database name
define("DATABASE_DB_NAME", 'microblog');
define("BASEPATH", 'framework/CI/');
############ 站点配置 ############
############ WEBSITE SETTINGS ############
// 网站名称
// Website name
define("SITE_NAME", 'PageCookery Microblog');
// 微博访问路径, 请以 / 结尾
// Website visit URL, End up with /
define("BASE_URL", 'http://localhost:8000/pagecookery/');
注意到我增加了一行。
define("BASEPATH", 'framework/CI/');
这是因为这个版本使用的CI框架已经很老了,对于新的MySQL数据库支持不是很好,需要一并更换CI框架的文件,推进使用3.1.1版本。而新版CI框架需要定义BASEPATH。
之后请依次对config.wordpress.php、config.language.php、文件中的define进行替换。
注意到,index.php中还有几行代码用于写入“config.language.php”文件,因此需要一并替换。
原代码:
$lang_config = " . Format::Safe($_POST['language'], TRUE) . "');";
$lang_config = " . Format::Safe(str_replace('.', '', $_GET['PG_LANG']), TRUE) . "');";
$wordpress_config = "\r\ndefine(WP_ENABLED, TRUE);\r\ndefine(WP_URL, '" . Format::Safe($_POST['wp_url'], TRUE) . "');\r\ndefine(WP_USERNAME, '" . Format::Safe($_POST['wp_username'], TRUE) . "');\r\ndefine(WP_PASSWORD, '" . Format::Safe($_POST['wp_password']) . "');\r\ndefine(WP_CATEGORY_ID, " . intval($_POST['wp_category_id']) . ");";
$wordpress_config = "\r\ndefine(WP_ENABLED, FALSE);\r\ndefine(WP_URL, '');\r\ndefine(WP_USERNAME, '');\r\ndefine(WP_PASSWORD, '');\r\ndefine(WP_CATEGORY_ID, 0);";
替换后为
$lang_config = " . Format::Safe($_POST['language'], TRUE) . "');";
$lang_config = " . Format::Safe(str_replace('.', '', $_GET['PG_LANG']), TRUE) . "');";
$wordpress_config = "\r\ndefine(\"WP_ENABLED\", TRUE);\r\ndefine(\"WP_URL\", '" . Format::Safe($_POST['wp_url'], TRUE) . "');\r\ndefine(\"WP_USERNAME\", '" . Format::Safe($_POST['wp_username'], TRUE) . "');\r\ndefine(\"WP_PASSWORD\", '" . Format::Safe($_POST['wp_password']) . "');\r\ndefine(\"WP_CATEGORY_ID\", " . intval($_POST['wp_category_id']) . ");";
$wordpress_config = ";
刷新一下,清爽多了。
Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in D:\xampp\htdocs\PC\init.php on line 61
Fatal error: 'continue' not in the 'loop' or 'switch' context in D:\xampp\htdocs\PC\framework\CI\database\DB.php on line 61
下面看init.php,由于__autoload被弃用,应对下面的代码进行修改。
function __autoload($class_name)
{
if (in_array(strtolower($class_name), array('cron', 'format', 'helper', 'image', 'iplocation', 'pages', 'rssparser', 'template', 'timer', 'upload', 'weiboclient', 'weibooauth')))
{
require_once(COOKERY_FRAMEWORK_DIR . 'lib/class_' . strtolower($class_name) . '.php');
}
}
修改为如下的代码:
spl_autoload_register('autoload');
function autoload($class_name)
{
if (in_array(strtolower($class_name), array('cron', 'format', 'helper', 'image', 'iplocation', 'pages', 'rssparser', 'template', 'timer', 'upload', 'weiboclient', 'weibooauth')))
{
require_once(COOKERY_FRAMEWORK_DIR . 'lib/class_' . strtolower($class_name) . '.php');
}
}
下面的致命错误,只需要对CI框架文件进行整体替换就可以了。
刷新一下。不容易啊,可以进入安装界面了。
选择语言,填写管理员用户名密码。
卡住了,刷新一下。
Warning: Use of undefined constant TIMENOW - assumed 'TIMENOW' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\PC\global.php on line 24
Fatal error: Uncaught Error: Call to undefined function log_message() in D:\xampp\htdocs\PC\framework\CI\database\DB_driver.php:375 Stack trace: #0 D:\xampp\htdocs\PC\framework\CI\database\DB.php(201): CI_DB_driver->__construct(Array) #1 D:\xampp\htdocs\PC\global.php(52): DB(Array) #2 D:\xampp\htdocs\PC\index.php(9): require_once('D:\\xampp\\htdocs...') #3 {main} thrown in D:\xampp\htdocs\PC\framework\CI\database\DB_driver.php on line 375
又报错了。第一条同之前的方案,修改define的引号。第二条,将报错代码注释掉即可。
再次刷新,新的错误出现了。
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in D:\xampp\htdocs\PC\lib\class_template.php on line 160
这是因为/e被弃用了,修改lib\class_template.php文件的如下行:
$template = preg_replace("/\{template (.+?)\}/e", "load_template('\\1')", $template);
修改为:
$template = preg_replace_callback("/\{template (.+?)\}/", function($matches) {
return load_template($matches[1]); }, $template);
刷新,又报错了。
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in D:\xampp\htdocs\PC\lib\functions.php on line 19
同理,修改lib\functions.php 文件的
$file_content = preg_replace("/\{template (.+?)\}/e", "load_template('\\1')", $file_content);
为
$file_content = preg_replace_callback("/\{template (.+?)\}/", function($matches) {
return load_template($matches[1]); }, $file_content);
大功告成了。
此外,这个IE版本提示放在今天已经不合适了,新版的edge和chrome浏览器仍会提示IE版本过低,可以在template/header.html中移去下面的代码。
<!--[if lt IE 7]>
{
template no_support_ie6}
<![endif]-->
上述修改后的版本我重新整理了一下,版本号修改为了0.9.10。欢迎大家一起讨论。
PageCookery 0.9.9原版下载
0.9.10稍后放出