<?php
class Andy_ChangeDate_ControllerPublic_Post extends XFCP_Andy_ChangeDate_ControllerPublic_Post
{
public function actionChangedate()
{
$post['post_id'] = $this->_input->filterSingle('post_id', XenForo_Input::UINT);
$viewParams = array('post' => $post,
);
if (XenForo_Visitor::getInstance()->isSuperAdmin())
{
return $this->responseView('Andy_DateChange_ViewPublic_Post','andy_changedate',$viewParams);
}
}
public function actionChangedatesave()
{
$this->_assertPostOnly();
// if you are not a super admin, you will get an error
if (!XenForo_Visitor::getInstance()->isSuperAdmin())
{
return;
}
$postId= $this->_input->filterSingle('post_id', XenForo_Input::UINT);
// get input text from template
$newPostDate = $this->_input->filterSingle('new_post_date', XenForo_Input::STRING);
if ($newPostDate == '')
{
return $this->responseError('Date Missing');
}
// get input text from template
$newPostTime = $this->_input->filterSingle('new_post_time', XenForo_Input::STRING);
if ($newPostTime == '')
{
return $this->responseError('Time Missing');
}
// convert to unix timestamp
date_default_timezone_set('America/Los_Angeles');
$date = $newPostDate . ' ' . $newPostTime;
$dateline = strtotime($date);
if ($dateline == '')
{
return $this->responseError('Date or Time format incorrect');
}
//########################################
// start database operations
//########################################
$db = XenForo_Application::getDb();
//########################################
// get thread_id
$query = "
SELECT thread_id
FROM xf_post
WHERE post_id='$postId'";
$thread_id = XenForo_Application::get('db')->fetchOne($query);
if ($thread_id == '')
{
return $this->responseError('Invalid post number in URL');
}
//########################################
// update xf_post
$db->query("
UPDATE xf_post
SET post_date='$dateline'
WHERE post_id='$postId'
LIMIT 1");
//#####################################
// get every post_id in thread
$query = $db->fetchAll("
SELECT post_id
FROM xf_post
WHERE thread_id='$thread_id'
ORDER BY post_date ASC");
foreach($query AS $rowName => $results)
{
$post_id[] = $results['post_id'];
}
$count = count($post_id);
//#####################################
// update xf_post.position for each post
for ($i=0; $i<$count; $i++)
{
$db->query("
UPDATE xf_post
SET position='$i'
WHERE post_id='$post_id[$i]'
LIMIT 1");
}
//#####################################
// update xf_thread first post info
$query = $db->fetchAll("
SELECT user_id, username
FROM xf_post
WHERE thread_id='$thread_id'
AND position='0'
LIMIT 1");
foreach($query AS $rowName => $results)
{
$user_id = $results['user_id'];
$username = $results['username'];
}
$db->query("
UPDATE xf_thread
SET user_id='$user_id', username='$username'
WHERE thread_id='$thread_id'
LIMIT 1");
//#####################################
// update xf_thread last post info
$last_position = $i - 1;
$query = $db->fetchAll("
SELECT post_date, post_id, user_id, username
FROM xf_post
WHERE thread_id='$thread_id'
AND position='$last_position'
LIMIT 1");
foreach($query AS $rowName => $results)
{
$last_post_date = $results['post_date'];
$last_post_id = $results['post_id'];
$last_post_user_id = $results['user_id'];
$last_post_username = $results['username'];
}
$db->query("
UPDATE xf_thread
SET last_post_date='$last_post_date', last_post_id='$last_post_id', last_post_user_id='$last_post_user_id', last_post_username='$last_post_username'
WHERE thread_id='$thread_id'
LIMIT 1");
// this variable is needed for the line below (XenForo_Link::buildPublicLink)
$post['post_id'] = $postId;
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildPublicLink('posts', $post),'Post Date Changed');
}
}
?>