<?php
/* PageCookery Microblog
*
* Author: Explon
*
* Copyright (C) 2007 Explon <explon@gmail.com>
*/


// Report all errors, except notices
error_reporting(E_ALL ^ E_NOTICE);

date_default_timezone_set('Asia/Chongqing');

require_once('config.php');
require_once('config.wordpress.php');
require_once('config.language.php');
require_once('init.php');
require_once('lib/functions_microblog.php');

define('WB_AKEY', '3665590334');
define('WB_SKEY', 'e2ef4d71015f1d2528b3a0ea130820bd');

define(TIMENOW, time());

$pcm_version = '0.9.8';
$pcm_build = 110610;

if ($_GET['act'] == 'install')
{
	if (file_exists('language/' . str_replace('.', '', $_GET['PG_LANG']) . '.php'))
	{
		require_once('language/' . str_replace('.', '', $_GET['PG_LANG']) . '.php');
	}
}
else
{
	if (file_exists('language/' . PG_LANG . '.php'))
	{
		require_once('language/' . PG_LANG . '.php');
	}
}

$is_guest = TRUE;
$guest_nickname = _t('匿名人士');

if (Helper::GetCookie('nickname'))
{
	$guest_nickname = Helper::GetCookie('nickname');
}

$db = DB($db_driver . '://' . DATABASE_USER . ':' . DATABASE_PSSWORD . '@' . DATABASE_HOST . '/' . DATABASE_DB_NAME .'?char_set=utf8&dbcollat=utf8_general_ci');

$_install_check = $db->query("SELECT id FROM user LIMIT 1");

if (!$_install_check AND $_GET['act'] != 'install')
{
	redirect(BASE_URL . '?act=install');
}

if ($_GET['act'] != 'install')
{
	if (Helper::GetCookie('username') AND Helper::GetCookie('password'))
	{
		$User = $db->query("SELECT * FROM user WHERE username = '" . Helper::GetCookie('username') . "' AND password = '" . Helper::GetCookie('password') . "'")->row_array();
	}

	if (is_array($User))
	{
		$is_guest = FALSE;
		$is_administrator = $User['administrator'];
	}

	$Own = $db->query("SELECT * FROM user WHERE id = 1")->row_array();

	$sync = @unserialize(stripslashes($Own['sync']));
	
	$flickr = @unserialize(stripslashes($Own['flickr']));
	
	$options = @unserialize(stripslashes($Own['options']));

	$time_24h =  TIMENOW - 3600 * 24;
	$time_week = TIMENOW - 3600 * 24 * 7;

	$stats_24h = $db->query("SELECT COUNT(id) AS count FROM entry WHERE time > " . $time_24h)->row_array();
	$stats_week = $db->query("SELECT COUNT(id) AS count FROM entry WHERE time > " . $time_week)->row_array();
	$stats_total = $db->query("SELECT COUNT(id) AS count FROM entry")->row_array();

	$stats = array(
		'24h' => $stats_24h['count'],
		'week' => $stats_week['count'],
		'total' => $stats_total['count'],
	);
}

if (isset($_GET['act']))
{
	$act = trim(strtolower($_GET['act']));
}