2015-06-26 06:31:53 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
2015-03-27 02:00:01 +01:00
|
|
|
|
2015-06-26 06:31:53 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
2015-11-20 04:21:39 +01:00
|
|
|
function updateBludit()
|
|
|
|
{
|
|
|
|
global $Site;
|
2016-01-22 05:26:00 +01:00
|
|
|
global $dbPosts;
|
2016-01-29 00:20:59 +01:00
|
|
|
global $dbPages;
|
2015-11-20 04:21:39 +01:00
|
|
|
|
|
|
|
// Check if Bludit need to be update.
|
2015-12-28 23:28:42 +01:00
|
|
|
if( ($Site->currentBuild() < BLUDIT_BUILD) || isset($_GET['update']) )
|
2015-11-20 04:21:39 +01:00
|
|
|
{
|
2016-07-17 01:19:10 +02:00
|
|
|
// LOG
|
|
|
|
Log::set('UPDATE SYSTEM - Starting...');
|
|
|
|
|
|
|
|
// LOG
|
|
|
|
Log::set('UPDATE SYSTEM - Checking posts.');
|
|
|
|
|
|
|
|
// Update posts
|
|
|
|
foreach($dbPosts->db as $key=>$post) {
|
|
|
|
|
|
|
|
// Dates
|
2016-01-22 05:26:00 +01:00
|
|
|
$date = Date::format($post['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
|
|
|
|
if($date !== false) {
|
2016-07-17 01:19:10 +02:00
|
|
|
$dbPosts->setPostDb($key, 'date', $date);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checksum
|
|
|
|
if( empty($post['md5file']) ) {
|
|
|
|
$checksum = md5_file(PATH_POSTS.$key.DS.FILENAME);
|
|
|
|
$dbPosts->setPostDb($key, 'md5file', $checksum);
|
2016-01-22 05:26:00 +01:00
|
|
|
}
|
2017-05-20 11:17:16 +02:00
|
|
|
|
|
|
|
// UUID
|
|
|
|
if( empty($post['uuid']) ) {
|
|
|
|
$uuid = uniqid();
|
|
|
|
$dbPosts->setPostDb($key, 'uuid', $uuid);
|
|
|
|
}
|
2016-01-22 05:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$dbPosts->save();
|
|
|
|
|
2016-07-17 01:19:10 +02:00
|
|
|
// LOG
|
|
|
|
Log::set('UPDATE SYSTEM - Checking pages.');
|
|
|
|
|
|
|
|
// Update pages
|
|
|
|
foreach($dbPages->db as $key=>$page) {
|
|
|
|
|
2016-01-29 00:03:15 +01:00
|
|
|
$date = Date::format($page['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
|
|
|
|
if($date !== false) {
|
2016-07-17 01:19:10 +02:00
|
|
|
$dbPages->setPageDb($key, 'date', $date);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checksum
|
2017-05-20 11:17:16 +02:00
|
|
|
if( empty($page['md5file']) ) {
|
2016-07-17 01:19:10 +02:00
|
|
|
$checksum = md5_file(PATH_PAGES.$key.DS.FILENAME);
|
|
|
|
$dbPages->setPageDb($key, 'md5file', $checksum);
|
2016-01-29 00:03:15 +01:00
|
|
|
}
|
2017-05-20 11:17:16 +02:00
|
|
|
|
|
|
|
// UUID
|
|
|
|
if( empty($page['uuid']) ) {
|
|
|
|
$uuid = uniqid();
|
|
|
|
$dbPages->setPostDb($key, 'uuid', $uuid);
|
|
|
|
}
|
2016-01-29 00:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$dbPages->save();
|
|
|
|
|
2016-07-17 01:19:10 +02:00
|
|
|
// LOG
|
|
|
|
Log::set('UPDATE SYSTEM - Checking directories.');
|
|
|
|
|
2016-01-22 05:26:00 +01:00
|
|
|
// --- Update directories ---
|
2015-12-28 23:28:42 +01:00
|
|
|
$directories = array(
|
|
|
|
PATH_POSTS,
|
|
|
|
PATH_PAGES,
|
|
|
|
PATH_PLUGINS_DATABASES,
|
|
|
|
PATH_UPLOADS_PROFILES,
|
|
|
|
PATH_UPLOADS_THUMBNAILS,
|
|
|
|
PATH_TMP
|
|
|
|
);
|
2015-11-20 04:21:39 +01:00
|
|
|
|
2016-07-17 01:19:10 +02:00
|
|
|
foreach($directories as $dir) {
|
|
|
|
|
2015-11-20 04:21:39 +01:00
|
|
|
// Check if the directory is already created.
|
|
|
|
if(!file_exists($dir)) {
|
|
|
|
// Create the directory recursive.
|
|
|
|
mkdir($dir, DIR_PERMISSIONS, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set and save the database.
|
|
|
|
$Site->set(array('currentBuild'=>BLUDIT_BUILD));
|
2015-12-28 23:28:42 +01:00
|
|
|
|
2016-07-17 01:19:10 +02:00
|
|
|
// LOG
|
|
|
|
Log::set('UPDATE SYSTEM - Updated...');
|
2015-11-20 04:21:39 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-27 02:00:01 +01:00
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Main before POST
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-06-26 06:31:53 +02:00
|
|
|
// ============================================================================
|
|
|
|
// POST Method
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ============================================================================
|
2015-08-03 02:49:12 +02:00
|
|
|
// Main after POST
|
2015-06-26 06:31:53 +02:00
|
|
|
// ============================================================================
|
|
|
|
|
2015-11-20 04:21:39 +01:00
|
|
|
// Try update Bludit
|
|
|
|
updateBludit();
|
|
|
|
|
|
|
|
// Get draft posts and schedules
|
2015-07-27 02:29:47 +02:00
|
|
|
$_draftPosts = array();
|
2015-10-22 05:14:22 +02:00
|
|
|
$_scheduledPosts = array();
|
2015-07-27 02:29:47 +02:00
|
|
|
foreach($posts as $Post)
|
|
|
|
{
|
2015-08-26 05:49:15 +02:00
|
|
|
if($Post->draft()) {
|
2015-07-27 02:29:47 +02:00
|
|
|
array_push($_draftPosts, $Post);
|
|
|
|
}
|
2015-10-22 05:14:22 +02:00
|
|
|
elseif($Post->scheduled()) {
|
|
|
|
array_push($_scheduledPosts, $Post);
|
|
|
|
}
|
2015-07-27 02:29:47 +02:00
|
|
|
}
|
|
|
|
|
2015-11-20 04:21:39 +01:00
|
|
|
// Get draft pages
|
2015-07-27 02:29:47 +02:00
|
|
|
$_draftPages = array();
|
|
|
|
foreach($pages as $Page)
|
|
|
|
{
|
|
|
|
if(!$Page->published()) {
|
|
|
|
array_push($_draftPages, $Page);
|
|
|
|
}
|
2015-08-29 07:02:09 +02:00
|
|
|
}
|