Add Above: (Ctrl + A to select all)
// [EN30] Ajax Thanks v1.0.0
private function doAjaxThanks()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$pid = intval( $this->request['pid'] );
$fid = intval( $this->request['fid'] );
$tid = intval( $this->request['tid'] );
//-----------------------------------------
// Permissions
//-----------------------------------------
if ( ! $pid || ! $tid || ! $fid )
{
$this->returnJsonError( 'No post/topic/forum passed.' );
}
$pass = 1;
if ( ! $this->settings['en30_ajaxthanks'] )
{
// Mod is off
$pass = 0;
}
if ( ! $this->memberData['member_id'] )
{
// Must be logged in
$pass = 0;
}
if ( in_array( $fid, explode( ",", $this->settings['en30_ajaxthanksforums'] ) ) )
{
// Forum excluded
$pass = 0;
}
if ( in_array( $this->memberData['member_group_id'], explode( ",", $this->settings['en30_ajaxthanksgroups'] ) ) )
{
// Group excluded
$pass = 0;
}
if ( ! $pass )
{
$this->returnJsonError( 'Unauthorized action.' );
}
$this->DB->build( array( 'select' => 'author_id, thankers', 'from' => 'posts', 'where' => "pid = '{$pid}' AND topic_id = '{$tid}'" ) );
$this->DB->execute();
if ( ! $this->DB->getTotalRows() )
{
$this->returnJsonError( 'Invalid post or topic ID.' );
}
$fetch = $this->DB->fetch();
if ( $fetch['author_id'] == $this->memberData['member_id'] )
{
$this->returnJsonError( 'You can\'t thank yourself, silly!' );
}
$serializedThankers = $fetch['thankers'];
$thankers = array( $this->memberData['member_id'] => $this->memberData['members_display_name'] );
if ( ! empty( $serializedThankers ) )
{
$serializedThankers = unserialize( stripslashes( $serializedThankers ) );
if ( array_key_exists( $this->memberData['member_id'], $serializedThankers ) )
{
$this->returnJsonError( 'You have already thanked this topic.' );
}
foreach ( $serializedThankers as $k => $v )
{
$thankers[ $k ] = $v;
}
}
$thankers = addslashes( serialize( $thankers ) );
$this->DB->update( 'posts', array( 'thankers' => $thankers ), 'pid='.$pid );
$this->DB->update( 'members', 'thanked=thanked+1', 'member_id='.$fetch['author_id'], false, true );
$this->returnJsonArray( array( 'mid' => $this->memberData['member_id'],
'members_display_name' => $this->memberData['members_display_name']
) );
}
// [EN30] Ajax Thanks v1.0.0