2002-07-14 14:37:47 +00:00
< ? php
2007-10-05 14:30:11 +00:00
/**
2005-04-09 12:26:45 +00:00
*
* @ package phpBB3
2007-10-05 14:30:11 +00:00
* @ copyright ( c ) 2005 phpBB Group
2011-12-31 13:32:52 +00:00
* @ license http :// opensource . org / licenses / gpl - 2.0 . php GNU General Public License v2
2005-04-09 12:26:45 +00:00
*
*/
2007-10-05 14:30:11 +00:00
/**
* @ ignore
*/
if ( ! defined ( 'IN_PHPBB' ))
{
exit ;
}
2005-04-09 12:26:45 +00:00
/**
2007-01-21 18:33:45 +00:00
* Fill smiley templates ( or just the variables ) with smilies , either in a window or inline
2005-04-09 12:26:45 +00:00
*/
2003-10-10 12:11:18 +00:00
function generate_smilies ( $mode , $forum_id )
2002-07-14 14:37:47 +00:00
{
2012-03-16 11:03:03 +01:00
global $db , $user , $config , $template , $phpbb_dispatcher ;
2014-05-05 13:13:48 -07:00
global $phpEx , $phpbb_root_path , $phpbb_container , $phpbb_path_helper ;
2003-02-27 23:37:02 +00:00
2014-01-26 17:54:50 -08:00
$base_url = append_sid ( " { $phpbb_root_path } posting. $phpEx " , 'mode=smilies&f=' . $forum_id );
$pagination = $phpbb_container -> get ( 'pagination' );
2009-07-17 09:05:09 +00:00
$start = request_var ( 'start' , 0 );
2002-11-07 22:02:04 +00:00
if ( $mode == 'window' )
2002-07-14 14:37:47 +00:00
{
2004-05-02 13:06:57 +00:00
if ( $forum_id )
2003-10-10 12:11:18 +00:00
{
2004-05-02 13:06:57 +00:00
$sql = ' SELECT forum_style
FROM ' . FORUMS_TABLE . "
WHERE forum_id = $forum_id " ;
$result = $db -> sql_query_limit ( $sql , 1 );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2007-11-27 15:13:50 +00:00
2004-05-02 13:06:57 +00:00
$user -> setup ( 'posting' , ( int ) $row [ 'forum_style' ]);
}
else
{
$user -> setup ( 'posting' );
}
2003-08-27 16:31:54 +00:00
2005-03-21 23:10:11 +00:00
page_header ( $user -> lang [ 'SMILIES' ]);
2009-07-17 09:05:09 +00:00
2010-02-08 16:43:39 +00:00
$sql = ' SELECT COUNT ( smiley_id ) AS item_count
2009-07-16 17:57:05 +00:00
FROM ' . SMILIES_TABLE . '
GROUP BY smiley_url ' ;
$result = $db -> sql_query ( $sql , 3600 );
2009-07-17 09:05:09 +00:00
2009-07-16 17:57:05 +00:00
$smiley_count = 0 ;
while ( $row = $db -> sql_fetchrow ( $result ))
{
++ $smiley_count ;
}
$db -> sql_freeresult ( $result );
2002-07-14 14:37:47 +00:00
2002-10-04 13:09:10 +00:00
$template -> set_filenames ( array (
2002-10-30 18:59:09 +00:00
'body' => 'posting_smilies.html' )
2002-10-04 13:09:10 +00:00
);
2009-07-17 09:05:09 +00:00
2014-01-26 17:54:50 -08:00
$start = $pagination -> validate_start ( $start , $config [ 'smilies_per_page' ], $smiley_count );
$pagination -> generate_template_pagination ( $base_url , 'pagination' , 'start' , $smiley_count , $config [ 'smilies_per_page' ], $start );
2002-10-04 13:09:10 +00:00
}
2002-07-14 14:37:47 +00:00
2004-01-25 14:30:15 +00:00
$display_link = false ;
2003-10-10 12:11:18 +00:00
if ( $mode == 'inline' )
{
2005-03-21 23:10:11 +00:00
$sql = ' SELECT smiley_id
2003-10-10 15:59:45 +00:00
FROM ' . SMILIES_TABLE . '
2003-10-10 16:08:46 +00:00
WHERE display_on_posting = 0 ' ;
2003-10-10 12:11:18 +00:00
$result = $db -> sql_query_limit ( $sql , 1 , 0 , 3600 );
2003-10-12 11:59:23 +00:00
2003-10-10 16:08:46 +00:00
if ( $row = $db -> sql_fetchrow ( $result ))
{
2004-01-25 14:30:15 +00:00
$display_link = true ;
2003-10-10 16:08:46 +00:00
}
2003-10-12 11:59:23 +00:00
$db -> sql_freeresult ( $result );
2003-10-10 12:11:18 +00:00
}
2009-07-16 17:57:05 +00:00
if ( $mode == 'window' )
{
2010-03-02 20:36:26 +01:00
$sql = ' SELECT smiley_url , MIN ( emotion ) as emotion , MIN ( code ) AS code , smiley_width , smiley_height , MIN ( smiley_order ) AS min_smiley_order
2009-07-16 17:57:05 +00:00
FROM ' . SMILIES_TABLE . '
2009-07-17 09:05:09 +00:00
GROUP BY smiley_url , smiley_width , smiley_height
2010-03-02 20:36:26 +01:00
ORDER BY min_smiley_order ' ;
2009-07-17 09:05:09 +00:00
$result = $db -> sql_query_limit ( $sql , $config [ 'smilies_per_page' ], $start , 3600 );
2009-07-16 17:57:05 +00:00
}
else
{
$sql = ' SELECT *
FROM ' . SMILIES_TABLE . '
WHERE display_on_posting = 1
ORDER BY smiley_order ' ;
$result = $db -> sql_query ( $sql , 3600 );
}
2002-07-14 14:37:47 +00:00
2007-05-17 11:59:06 +00:00
$smilies = array ();
2003-10-10 16:08:46 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
2002-10-04 13:09:10 +00:00
{
2007-05-17 11:59:06 +00:00
if ( empty ( $smilies [ $row [ 'smiley_url' ]]))
{
$smilies [ $row [ 'smiley_url' ]] = $row ;
}
}
$db -> sql_freeresult ( $result );
if ( sizeof ( $smilies ))
{
2014-05-05 13:13:48 -07:00
$root_path = ( defined ( 'PHPBB_USE_BOARD_URL_PATH' ) && PHPBB_USE_BOARD_URL_PATH ) ? generate_board_url () . '/' : $phpbb_path_helper -> get_web_root_path ();
2009-08-17 14:45:14 +00:00
2007-05-17 11:59:06 +00:00
foreach ( $smilies as $row )
2006-04-22 18:54:41 +00:00
{
$template -> assign_block_vars ( 'smiley' , array (
2006-05-06 15:15:40 +00:00
'SMILEY_CODE' => $row [ 'code' ],
'A_SMILEY_CODE' => addslashes ( $row [ 'code' ]),
2009-08-17 14:45:14 +00:00
'SMILEY_IMG' => $root_path . $config [ 'smilies_path' ] . '/' . $row [ 'smiley_url' ],
2006-05-06 15:15:40 +00:00
'SMILEY_WIDTH' => $row [ 'smiley_width' ],
'SMILEY_HEIGHT' => $row [ 'smiley_height' ],
'SMILEY_DESC' => $row [ 'emotion' ])
2006-04-22 18:54:41 +00:00
);
}
2002-07-14 14:37:47 +00:00
}
2012-08-04 17:07:35 +02:00
/**
2012-08-20 10:10:52 +02:00
* This event is called after the smilies are populated
2012-08-04 17:07:35 +02:00
*
* @ event core . generate_smilies_after
* @ var string mode Mode of the smilies : window | inline
* @ var int forum_id The forum ID we are currently in
* @ var bool display_link Shall we display the " more smilies " link ?
2014-04-25 12:15:44 +02:00
* @ since 3.1 . 0 - a1
2012-08-04 17:07:35 +02:00
*/
$vars = array ( 'mode' , 'forum_id' , 'display_link' );
extract ( $phpbb_dispatcher -> trigger_event ( 'core.generate_smilies_after' , compact ( $vars )));
2003-10-10 16:08:46 +00:00
if ( $mode == 'inline' && $display_link )
{
$template -> assign_vars ( array (
2005-03-21 23:10:11 +00:00
'S_SHOW_SMILEY_LINK' => true ,
2014-01-26 17:54:50 -08:00
'U_MORE_SMILIES' => $base_url ,
));
2003-10-10 16:08:46 +00:00
}
2002-10-30 18:59:09 +00:00
if ( $mode == 'window' )
2002-07-14 14:37:47 +00:00
{
2003-05-25 14:32:20 +00:00
page_footer ();
2002-07-14 14:37:47 +00:00
}
}
2005-04-09 12:26:45 +00:00
/**
2006-12-21 10:37:50 +00:00
* Update last post information
2006-11-24 14:59:26 +00:00
* Should be used instead of sync () if only the last post information are out of sync ... faster
2006-05-12 20:52:58 +00:00
*
2007-04-15 10:59:26 +00:00
* @ param string $type Can be forum | topic
* @ param mixed $ids topic / forum ids
* @ param bool $return_update_sql true : SQL query shall be returned , false : execute SQL
2005-04-09 12:26:45 +00:00
*/
2007-05-09 02:19:31 +00:00
function update_post_information ( $type , $ids , $return_update_sql = false )
2003-04-19 10:28:37 +00:00
{
global $db ;
2007-06-26 14:27:22 +00:00
if ( empty ( $ids ))
{
return ;
}
2006-01-22 13:06:13 +00:00
if ( ! is_array ( $ids ))
{
$ids = array ( $ids );
}
2003-04-19 10:28:37 +00:00
2006-10-19 13:55:48 +00:00
$update_sql = $empty_forums = $not_empty_forums = array ();
2005-01-29 14:46:16 +00:00
2007-03-14 21:40:52 +00:00
if ( $type != 'topic' )
{
$topic_join = ', ' . TOPICS_TABLE . ' t' ;
2010-06-17 23:58:18 -05:00
$topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_visibility = ' . ITEM_APPROVED ;
2007-03-14 21:40:52 +00:00
}
else
{
$topic_join = '' ;
$topic_condition = '' ;
}
2006-09-13 16:08:36 +00:00
if ( sizeof ( $ids ) == 1 )
{
2007-03-14 21:40:52 +00:00
$sql = ' SELECT MAX ( p . post_id ) as last_post_id
FROM ' . POSTS_TABLE . " p $topic_join
WHERE " . $db->sql_in_set ('p.' . $type . '_id', $ids ) . "
$topic_condition
2010-06-17 23:58:18 -05:00
AND p . post_visibility = " . ITEM_APPROVED;
2006-09-13 16:08:36 +00:00
}
else
{
2007-03-14 21:40:52 +00:00
$sql = 'SELECT p.' . $type . ' _id , MAX ( p . post_id ) as last_post_id
FROM ' . POSTS_TABLE . " p $topic_join
WHERE " . $db->sql_in_set ('p.' . $type . '_id', $ids ) . "
$topic_condition
2010-06-17 23:58:18 -05:00
AND p . post_visibility = " . ITEM_APPROVED . "
2007-03-14 21:40:52 +00:00
GROUP BY p . { $type } _id " ;
2006-09-13 16:08:36 +00:00
}
2003-11-22 12:43:07 +00:00
$result = $db -> sql_query ( $sql );
2003-04-19 10:28:37 +00:00
2006-01-22 13:06:13 +00:00
$last_post_ids = array ();
while ( $row = $db -> sql_fetchrow ( $result ))
{
2006-09-13 16:08:36 +00:00
if ( sizeof ( $ids ) == 1 )
{
$row [ $type . '_id' ] = $ids [ 0 ];
}
2006-01-22 13:06:13 +00:00
if ( $type == 'forum' )
{
2006-10-19 13:55:48 +00:00
$not_empty_forums [] = $row [ 'forum_id' ];
if ( empty ( $row [ 'last_post_id' ]))
{
$empty_forums [] = $row [ 'forum_id' ];
}
2006-01-22 13:06:13 +00:00
}
$last_post_ids [] = $row [ 'last_post_id' ];
}
$db -> sql_freeresult ( $result );
if ( $type == 'forum' )
{
2006-10-19 13:55:48 +00:00
$empty_forums = array_merge ( $empty_forums , array_diff ( $ids , $not_empty_forums ));
2006-01-22 13:06:13 +00:00
foreach ( $empty_forums as $void => $forum_id )
{
$update_sql [ $forum_id ][] = 'forum_last_post_id = 0' ;
2006-09-08 18:00:38 +00:00
$update_sql [ $forum_id ][] = " forum_last_post_subject = '' " ;
2006-08-22 11:01:56 +00:00
$update_sql [ $forum_id ][] = 'forum_last_post_time = 0' ;
2006-01-22 13:06:13 +00:00
$update_sql [ $forum_id ][] = 'forum_last_poster_id = 0' ;
$update_sql [ $forum_id ][] = " forum_last_poster_name = '' " ;
2006-08-22 11:01:56 +00:00
$update_sql [ $forum_id ][] = " forum_last_poster_colour = '' " ;
2006-01-22 13:06:13 +00:00
}
}
if ( sizeof ( $last_post_ids ))
2003-09-07 15:23:55 +00:00
{
2006-09-08 18:00:38 +00:00
$sql = 'SELECT p.' . $type . ' _id , p . post_id , p . post_subject , p . post_time , p . poster_id , p . post_username , u . user_id , u . username , u . user_colour
2003-11-22 12:43:07 +00:00
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . ' u
WHERE p . poster_id = u . user_id
2006-08-12 13:14:39 +00:00
AND ' . $db->sql_in_set(' p . post_id ' , $last_post_ids );
2003-11-22 12:43:07 +00:00
$result = $db -> sql_query ( $sql );
2006-01-22 13:06:13 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
{
$update_sql [ $row [ " { $type } _id " ]][] = $type . '_last_post_id = ' . ( int ) $row [ 'post_id' ];
2006-09-08 18:00:38 +00:00
$update_sql [ $row [ " { $type } _id " ]][] = " { $type } _last_post_subject = ' " . $db -> sql_escape ( $row [ 'post_subject' ]) . " ' " ;
2006-01-22 13:06:13 +00:00
$update_sql [ $row [ " { $type } _id " ]][] = $type . '_last_post_time = ' . ( int ) $row [ 'post_time' ];
$update_sql [ $row [ " { $type } _id " ]][] = $type . '_last_poster_id = ' . ( int ) $row [ 'poster_id' ];
2006-08-22 11:01:56 +00:00
$update_sql [ $row [ " { $type } _id " ]][] = " { $type } _last_poster_colour = ' " . $db -> sql_escape ( $row [ 'user_colour' ]) . " ' " ;
2006-01-22 13:06:13 +00:00
$update_sql [ $row [ " { $type } _id " ]][] = " { $type } _last_poster_name = ' " . (( $row [ 'poster_id' ] == ANONYMOUS ) ? $db -> sql_escape ( $row [ 'post_username' ]) : $db -> sql_escape ( $row [ 'username' ])) . " ' " ;
}
$db -> sql_freeresult ( $result );
2003-09-07 15:23:55 +00:00
}
2006-01-22 13:06:13 +00:00
unset ( $empty_forums , $ids , $last_post_ids );
2006-05-12 20:52:58 +00:00
if ( $return_update_sql || ! sizeof ( $update_sql ))
2003-09-07 15:23:55 +00:00
{
2006-05-12 20:52:58 +00:00
return $update_sql ;
2003-09-07 15:23:55 +00:00
}
2003-11-22 12:43:07 +00:00
2006-01-22 13:06:13 +00:00
$table = ( $type == 'forum' ) ? FORUMS_TABLE : TOPICS_TABLE ;
foreach ( $update_sql as $update_id => $update_sql_ary )
{
$sql = " UPDATE $table
SET " . implode(', ', $update_sql_ary ) . "
WHERE { $type } _id = $update_id " ;
$db -> sql_query ( $sql );
}
2006-05-26 15:04:27 +00:00
return ;
2003-04-19 10:28:37 +00:00
}
2006-05-12 20:52:58 +00:00
/**
* Generate Topic Icons for display
*/
function posting_gen_topic_icons ( $mode , $icon_id )
{
global $phpbb_root_path , $config , $template , $cache ;
// Grab icons
2006-11-12 15:35:43 +00:00
$icons = $cache -> obtain_icons ();
2006-05-12 20:52:58 +00:00
if ( ! $icon_id )
{
$template -> assign_var ( 'S_NO_ICON_CHECKED' , ' checked="checked"' );
}
2006-06-06 20:53:46 +00:00
2006-05-12 20:52:58 +00:00
if ( sizeof ( $icons ))
{
2012-07-23 14:28:47 +02:00
$root_path = ( defined ( 'PHPBB_USE_BOARD_URL_PATH' ) && PHPBB_USE_BOARD_URL_PATH ) ? generate_board_url () . '/' : $phpbb_root_path ;
2006-05-12 20:52:58 +00:00
foreach ( $icons as $id => $data )
{
if ( $data [ 'display' ])
{
$template -> assign_block_vars ( 'topic_icon' , array (
'ICON_ID' => $id ,
2012-07-23 14:28:47 +02:00
'ICON_IMG' => $root_path . $config [ 'icons_path' ] . '/' . $data [ 'img' ],
2006-05-12 20:52:58 +00:00
'ICON_WIDTH' => $data [ 'width' ],
2006-06-06 20:53:46 +00:00
'ICON_HEIGHT' => $data [ 'height' ],
One commit for those fixes having a very tiny impact (mostly only whitespaces or forgotten spans, etc.)
Although i somehow mistakingly got #20445 and #15249 into it. :/
Removing s_watching_img from watch_topic_forum() function (Bug #20445)
Changing order for post review if more than one post affected (Bug #15249)
Language typos/fixes (Bug #20425, #15719, #15429, #14669, #13479)
Style/Template fixes (Bug #20065, #19405, #19205, #15028, #14934, #14821, #14752, #14497, #13707, #14738)
Tiny code fixes (Bug #20165, #20025, #19795, #14804)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8350 89ea8834-ac86-4346-8a33-228a782c2dd0
2008-01-30 16:01:15 +00:00
2006-05-12 20:52:58 +00:00
'S_CHECKED' => ( $id == $icon_id ) ? true : false ,
'S_ICON_CHECKED' => ( $id == $icon_id ) ? ' checked="checked"' : '' )
);
}
}
return true ;
}
return false ;
}
/**
* Build topic types able to be selected
*/
function posting_gen_topic_types ( $forum_id , $cur_topic_type = POST_NORMAL )
{
global $auth , $user , $template , $topic_type ;
$toggle = false ;
$topic_types = array (
'sticky' => array ( 'const' => POST_STICKY , 'lang' => 'POST_STICKY' ),
'announce' => array ( 'const' => POST_ANNOUNCE , 'lang' => 'POST_ANNOUNCEMENT' ),
'global' => array ( 'const' => POST_GLOBAL , 'lang' => 'POST_GLOBAL' )
);
2006-06-06 20:53:46 +00:00
2006-05-12 20:52:58 +00:00
$topic_type_array = array ();
2006-06-06 20:53:46 +00:00
2006-05-12 20:52:58 +00:00
foreach ( $topic_types as $auth_key => $topic_value )
{
// We do not have a special post global announcement permission
$auth_key = ( $auth_key == 'global' ) ? 'announce' : $auth_key ;
if ( $auth -> acl_get ( 'f_' . $auth_key , $forum_id ))
{
$toggle = true ;
$topic_type_array [] = array (
'VALUE' => $topic_value [ 'const' ],
2010-03-11 16:03:14 +01:00
'S_CHECKED' => ( $cur_topic_type == $topic_value [ 'const' ]) ? ' checked="checked"' : '' ,
2006-05-12 20:52:58 +00:00
'L_TOPIC_TYPE' => $user -> lang [ $topic_value [ 'lang' ]]
);
}
}
if ( $toggle )
{
$topic_type_array = array_merge ( array ( 0 => array (
'VALUE' => POST_NORMAL ,
2010-05-28 14:25:56 +02:00
'S_CHECKED' => ( $cur_topic_type == POST_NORMAL ) ? ' checked="checked"' : '' ,
2007-10-05 14:30:11 +00:00
'L_TOPIC_TYPE' => $user -> lang [ 'POST_NORMAL' ])),
2006-06-06 20:53:46 +00:00
2006-05-12 20:52:58 +00:00
$topic_type_array
);
One commit for those fixes having a very tiny impact (mostly only whitespaces or forgotten spans, etc.)
Although i somehow mistakingly got #20445 and #15249 into it. :/
Removing s_watching_img from watch_topic_forum() function (Bug #20445)
Changing order for post review if more than one post affected (Bug #15249)
Language typos/fixes (Bug #20425, #15719, #15429, #14669, #13479)
Style/Template fixes (Bug #20065, #19405, #19205, #15028, #14934, #14821, #14752, #14497, #13707, #14738)
Tiny code fixes (Bug #20165, #20025, #19795, #14804)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8350 89ea8834-ac86-4346-8a33-228a782c2dd0
2008-01-30 16:01:15 +00:00
2006-05-12 20:52:58 +00:00
foreach ( $topic_type_array as $array )
{
$template -> assign_block_vars ( 'topic_type' , $array );
}
$template -> assign_vars ( array (
'S_TOPIC_TYPE_STICKY' => ( $auth -> acl_get ( 'f_sticky' , $forum_id )),
'S_TOPIC_TYPE_ANNOUNCE' => ( $auth -> acl_get ( 'f_announce' , $forum_id )))
);
}
return $toggle ;
}
//
// Attachment related functions
//
2005-04-09 12:26:45 +00:00
/**
* Upload Attachment - filedata is generated here
* Uses upload class
2013-10-11 17:40:16 +02:00
*
* @ param string $form_name The form name of the file upload input
* @ param int $forum_id The id of the forum
* @ param bool $local Whether the file is local or not
* @ param string $local_storage The path to the local file
* @ param bool $is_message Whether it is a PM or not
* @ param \filespec $local_filedata A filespec object created for the local file
* @ param \phpbb\plupload\plupload $plupload The plupload object if one is being used
*
* @ return object filespec
2005-04-09 12:26:45 +00:00
*/
2013-10-11 17:40:16 +02:00
function upload_attachment ( $form_name , $forum_id , $local = false , $local_storage = '' , $is_message = false , $local_filedata = false , \phpbb\plupload\plupload $plupload = null )
2003-04-19 12:58:37 +00:00
{
2005-10-02 18:17:06 +00:00
global $auth , $user , $config , $db , $cache ;
2006-06-06 20:53:46 +00:00
global $phpbb_root_path , $phpEx ;
2003-03-12 14:21:57 +00:00
2006-05-12 20:52:58 +00:00
$filedata = array (
'error' => array ()
);
2005-03-21 23:10:11 +00:00
2006-06-06 20:53:46 +00:00
include_once ( $phpbb_root_path . 'includes/functions_upload.' . $phpEx );
2005-03-21 23:10:11 +00:00
$upload = new fileupload ();
2006-06-06 20:53:46 +00:00
2010-10-28 21:41:14 +02:00
if ( $config [ 'check_attachment_content' ] && isset ( $config [ 'mime_triggers' ]))
2008-05-15 14:10:11 +00:00
{
$upload -> set_disallowed_content ( explode ( '|' , $config [ 'mime_triggers' ]));
}
2014-04-03 15:55:18 +02:00
else if ( ! $config [ 'check_attachment_content' ])
{
$upload -> set_disallowed_content ( array ());
}
2008-06-21 16:05:02 +00:00
2013-03-04 02:46:12 +01:00
$filedata [ 'post_attach' ] = $local || $upload -> is_valid ( $form_name );
2003-03-12 14:21:57 +00:00
2003-04-19 12:58:37 +00:00
if ( ! $filedata [ 'post_attach' ])
2003-03-12 14:21:57 +00:00
{
2006-09-13 16:08:36 +00:00
$filedata [ 'error' ][] = $user -> lang [ 'NO_UPLOAD_FORM_FOUND' ];
2003-04-20 16:49:26 +00:00
return $filedata ;
2003-03-12 14:21:57 +00:00
}
2003-04-19 12:58:37 +00:00
2006-12-27 17:43:55 +00:00
$extensions = $cache -> obtain_attach_extensions ((( $is_message ) ? false : ( int ) $forum_id ));
2005-03-21 23:10:11 +00:00
$upload -> set_allowed_extensions ( array_keys ( $extensions [ '_allowed_' ]));
2004-05-02 13:06:57 +00:00
2013-10-11 17:40:16 +02:00
$file = ( $local ) ? $upload -> local_upload ( $local_storage , $local_filedata ) : $upload -> form_upload ( $form_name , $plupload );
2004-12-12 14:07:02 +00:00
2005-03-21 23:10:11 +00:00
if ( $file -> init_error )
2004-12-12 14:07:02 +00:00
{
$filedata [ 'post_attach' ] = false ;
return $filedata ;
}
2013-03-04 02:43:48 +01:00
// Whether the uploaded file is in the image category
$is_image = ( isset ( $extensions [ $file -> get ( 'extension' )][ 'display_cat' ])) ? $extensions [ $file -> get ( 'extension' )][ 'display_cat' ] == ATTACHMENT_CATEGORY_IMAGE : false ;
2003-05-11 16:21:35 +00:00
2006-06-10 23:53:20 +00:00
if ( ! $auth -> acl_get ( 'a_' ) && ! $auth -> acl_get ( 'm_' , $forum_id ))
2003-04-19 12:58:37 +00:00
{
2013-03-04 02:39:44 +01:00
// Check Image Size, if it is an image
2013-03-04 02:43:48 +01:00
if ( $is_image )
2013-03-04 02:39:44 +01:00
{
$file -> upload -> set_allowed_dimensions ( 0 , 0 , $config [ 'img_max_width' ], $config [ 'img_max_height' ]);
}
// Admins and mods are allowed to exceed the allowed filesize
2006-07-10 15:55:10 +00:00
if ( ! empty ( $extensions [ $file -> get ( 'extension' )][ 'max_filesize' ]))
{
$allowed_filesize = $extensions [ $file -> get ( 'extension' )][ 'max_filesize' ];
}
else
{
$allowed_filesize = ( $is_message ) ? $config [ 'max_filesize_pm' ] : $config [ 'max_filesize' ];
}
2005-03-21 23:10:11 +00:00
$file -> upload -> set_max_filesize ( $allowed_filesize );
}
2006-06-06 20:53:46 +00:00
2005-03-21 23:10:11 +00:00
$file -> clean_filename ( 'unique' , $user -> data [ 'user_id' ] . '_' );
2007-05-17 13:23:13 +00:00
2013-03-04 02:43:48 +01:00
// Are we uploading an image *and* this image being within the image category?
// Only then perform additional image checks.
$file -> move_file ( $config [ 'upload_path' ], false , ! $is_image );
2007-05-17 13:23:13 +00:00
2013-03-04 02:49:48 +01:00
// Do we have to create a thumbnail?
$filedata [ 'thumbnail' ] = ( $is_image && $config [ 'img_create_thumbnail' ]) ? 1 : 0 ;
2006-06-06 20:53:46 +00:00
2005-03-21 23:10:11 +00:00
if ( sizeof ( $file -> error ))
{
$file -> remove ();
$filedata [ 'error' ] = array_merge ( $filedata [ 'error' ], $file -> error );
2004-01-25 14:30:15 +00:00
$filedata [ 'post_attach' ] = false ;
2004-12-12 14:07:02 +00:00
2003-04-20 16:49:26 +00:00
return $filedata ;
2003-03-22 15:48:46 +00:00
}
2003-04-19 12:58:37 +00:00
2013-05-25 10:50:43 +05:30
// Make sure the image category only holds valid images...
2013-03-04 02:43:48 +01:00
if ( $is_image && ! $file -> is_image ())
2013-05-25 10:50:43 +05:30
{
$file -> remove ();
2013-10-11 17:40:16 +02:00
if ( $plupload && $plupload -> is_active ())
{
$plupload -> emit_error ( 104 , 'ATTACHED_IMAGE_NOT_IMAGE' );
}
2013-05-25 10:50:43 +05:30
// If this error occurs a user tried to exploit an IE Bug by renaming extensions
// Since the image category is displaying content inline we need to catch this.
trigger_error ( $user -> lang [ 'ATTACHED_IMAGE_NOT_IMAGE' ]);
}
2005-03-21 23:10:11 +00:00
$filedata [ 'filesize' ] = $file -> get ( 'filesize' );
$filedata [ 'mimetype' ] = $file -> get ( 'mimetype' );
$filedata [ 'extension' ] = $file -> get ( 'extension' );
$filedata [ 'physical_filename' ] = $file -> get ( 'realname' );
$filedata [ 'real_filename' ] = $file -> get ( 'uploadname' );
$filedata [ 'filetime' ] = time ();
2003-04-19 12:58:37 +00:00
// Check our complete quota
2003-11-16 21:53:56 +00:00
if ( $config [ 'attachment_quota' ])
2003-03-22 15:48:46 +00:00
{
2005-03-21 23:10:11 +00:00
if ( $config [ 'upload_dir_size' ] + $file -> get ( 'filesize' ) > $config [ 'attachment_quota' ])
2003-03-22 15:48:46 +00:00
{
2003-05-11 16:21:35 +00:00
$filedata [ 'error' ][] = $user -> lang [ 'ATTACH_QUOTA_REACHED' ];
2004-01-25 14:30:15 +00:00
$filedata [ 'post_attach' ] = false ;
2004-12-12 14:07:02 +00:00
2005-03-21 23:10:11 +00:00
$file -> remove ();
2004-12-12 14:07:02 +00:00
2003-04-20 16:49:26 +00:00
return $filedata ;
2003-03-22 15:48:46 +00:00
}
2003-04-19 12:58:37 +00:00
}
2003-03-22 15:48:46 +00:00
2005-04-09 12:26:45 +00:00
// Check free disk space
if ( $free_space = @ disk_free_space ( $phpbb_root_path . $config [ 'upload_path' ]))
2003-11-16 21:53:56 +00:00
{
2005-03-21 23:10:11 +00:00
if ( $free_space <= $file -> get ( 'filesize' ))
2003-11-16 21:53:56 +00:00
{
2012-03-19 15:08:28 -04:00
if ( $auth -> acl_get ( 'a_' ))
{
$filedata [ 'error' ][] = $user -> lang [ 'ATTACH_DISK_FULL' ];
}
else
{
$filedata [ 'error' ][] = $user -> lang [ 'ATTACH_QUOTA_REACHED' ];
}
2004-01-25 14:30:15 +00:00
$filedata [ 'post_attach' ] = false ;
2003-03-22 15:48:46 +00:00
2005-03-21 23:10:11 +00:00
$file -> remove ();
2006-06-06 20:53:46 +00:00
2004-12-12 14:07:02 +00:00
return $filedata ;
}
2003-03-22 15:48:46 +00:00
}
2003-04-19 12:58:37 +00:00
2005-03-21 23:10:11 +00:00
// Create Thumbnail
2003-06-20 17:20:22 +00:00
if ( $filedata [ 'thumbnail' ])
2003-03-22 15:48:46 +00:00
{
2005-03-21 23:10:11 +00:00
$source = $file -> get ( 'destination_file' );
$destination = $file -> get ( 'destination_path' ) . '/thumb_' . $file -> get ( 'realname' );
2003-03-22 15:48:46 +00:00
2005-03-21 23:10:11 +00:00
if ( ! create_thumbnail ( $source , $destination , $file -> get ( 'mimetype' )))
2003-03-22 15:48:46 +00:00
{
2005-03-21 23:10:11 +00:00
$filedata [ 'thumbnail' ] = 0 ;
2003-03-22 15:48:46 +00:00
}
2003-06-20 17:20:22 +00:00
}
2003-08-27 16:31:54 +00:00
2005-03-21 23:10:11 +00:00
return $filedata ;
2003-04-19 12:58:37 +00:00
}
2005-04-09 12:26:45 +00:00
/**
* Calculate the needed size for Thumbnail
*/
2003-06-20 17:20:22 +00:00
function get_img_size_format ( $width , $height )
{
2006-08-28 15:50:33 +00:00
global $config ;
2004-07-08 22:41:04 +00:00
// Maximum Width the Image can take
2006-08-28 15:50:33 +00:00
$max_width = ( $config [ 'img_max_thumb_width' ]) ? $config [ 'img_max_thumb_width' ] : 400 ;
2003-06-20 17:20:22 +00:00
2004-07-08 22:41:04 +00:00
if ( $width > $height )
2003-06-20 17:20:22 +00:00
{
2004-07-08 22:41:04 +00:00
return array (
round ( $width * ( $max_width / $width )),
round ( $height * ( $max_width / $width ))
);
2006-06-06 20:53:46 +00:00
}
else
2003-06-20 17:20:22 +00:00
{
2004-07-08 22:41:04 +00:00
return array (
round ( $width * ( $max_width / $height )),
round ( $height * ( $max_width / $height ))
);
2003-06-20 17:20:22 +00:00
}
}
2005-04-09 12:26:45 +00:00
/**
* Return supported image types
*/
2005-01-02 19:08:07 +00:00
function get_supported_image_types ( $type = false )
2003-06-20 17:20:22 +00:00
{
if ( @ extension_loaded ( 'gd' ))
{
2004-07-08 22:41:04 +00:00
$format = imagetypes ();
$new_type = 0 ;
2005-01-02 19:08:07 +00:00
if ( $type !== false )
2003-06-20 17:20:22 +00:00
{
2008-04-21 12:18:36 +00:00
// Type is one of the IMAGETYPE constants - it is fetched from getimagesize()
2005-01-02 19:08:07 +00:00
switch ( $type )
{
2006-06-07 08:35:13 +00:00
// GIF
2010-09-10 00:10:40 +01:00
case IMAGETYPE_GIF :
2006-06-07 08:35:13 +00:00
$new_type = ( $format & IMG_GIF ) ? IMG_GIF : false ;
2006-05-12 20:52:58 +00:00
break ;
2006-06-07 08:35:13 +00:00
// JPG, JPC, JP2
2010-09-10 00:10:40 +01:00
case IMAGETYPE_JPEG :
case IMAGETYPE_JPC :
case IMAGETYPE_JPEG2000 :
case IMAGETYPE_JP2 :
case IMAGETYPE_JPX :
case IMAGETYPE_JB2 :
2006-06-07 08:35:13 +00:00
$new_type = ( $format & IMG_JPG ) ? IMG_JPG : false ;
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2006-06-07 08:35:13 +00:00
// PNG
2010-09-10 00:10:40 +01:00
case IMAGETYPE_PNG :
2006-06-07 08:35:13 +00:00
$new_type = ( $format & IMG_PNG ) ? IMG_PNG : false ;
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2008-04-21 12:18:36 +00:00
// WBMP
2010-09-10 00:10:40 +01:00
case IMAGETYPE_WBMP :
2006-06-07 08:35:13 +00:00
$new_type = ( $format & IMG_WBMP ) ? IMG_WBMP : false ;
2006-05-12 20:52:58 +00:00
break ;
2005-01-02 19:08:07 +00:00
}
}
else
{
$new_type = array ();
$go_through_types = array ( IMG_GIF , IMG_JPG , IMG_PNG , IMG_WBMP );
foreach ( $go_through_types as $check_type )
{
if ( $format & $check_type )
{
$new_type [] = $check_type ;
}
}
2003-06-20 17:20:22 +00:00
}
2006-06-06 20:53:46 +00:00
2004-07-08 22:41:04 +00:00
return array (
'gd' => ( $new_type ) ? true : false ,
'format' => $new_type ,
'version' => ( function_exists ( 'imagecreatetruecolor' )) ? 2 : 1
);
}
return array ( 'gd' => false );
2003-06-20 17:20:22 +00:00
}
2005-04-09 12:26:45 +00:00
/**
* Create Thumbnail
*/
2007-10-05 14:30:11 +00:00
function create_thumbnail ( $source , $destination , $mimetype )
2003-06-20 17:20:22 +00:00
{
global $config ;
2003-06-25 19:49:59 +00:00
$min_filesize = ( int ) $config [ 'img_min_thumb_filesize' ];
2004-01-25 14:30:15 +00:00
$img_filesize = ( file_exists ( $source )) ? @ filesize ( $source ) : false ;
2003-06-20 17:20:22 +00:00
2003-06-25 19:49:59 +00:00
if ( ! $img_filesize || $img_filesize <= $min_filesize )
2003-06-20 17:20:22 +00:00
{
2004-01-25 14:30:15 +00:00
return false ;
2003-06-20 17:20:22 +00:00
}
2006-05-12 20:52:58 +00:00
2007-05-19 16:40:56 +00:00
$dimension = @ getimagesize ( $source );
2003-06-20 17:20:22 +00:00
2007-03-08 15:49:13 +00:00
if ( $dimension === false )
{
return false ;
}
list ( $width , $height , $type , ) = $dimension ;
2007-05-07 21:21:40 +00:00
if ( empty ( $width ) || empty ( $height ))
2003-06-20 17:20:22 +00:00
{
2004-01-25 14:30:15 +00:00
return false ;
2003-06-20 17:20:22 +00:00
}
2004-07-08 22:41:04 +00:00
list ( $new_width , $new_height ) = get_img_size_format ( $width , $height );
2003-06-20 17:20:22 +00:00
2006-11-18 16:27:35 +00:00
// Do not create a thumbnail if the resulting width/height is bigger than the original one
2009-04-17 15:35:56 +00:00
if ( $new_width >= $width && $new_height >= $height )
2006-11-18 16:27:35 +00:00
{
return false ;
}
2004-01-25 14:30:15 +00:00
$used_imagick = false ;
2003-06-20 17:20:22 +00:00
2006-07-01 19:11:52 +00:00
// Only use imagemagick if defined and the passthru function not disabled
if ( $config [ 'img_imagick' ] && function_exists ( 'passthru' ))
2003-06-20 17:20:22 +00:00
{
2008-01-07 19:29:50 +00:00
if ( substr ( $config [ 'img_imagick' ], - 1 ) !== '/' )
2008-01-06 17:00:09 +00:00
{
2008-01-07 19:29:50 +00:00
$config [ 'img_imagick' ] .= '/' ;
2008-01-06 17:00:09 +00:00
}
2009-03-16 15:27:25 +00:00
@ passthru ( escapeshellcmd ( $config [ 'img_imagick' ]) . 'convert' . (( defined ( 'PHP_OS' ) && preg_match ( '#^win#i' , PHP_OS )) ? '.exe' : '' ) . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace ( '\\' , '/' , $source ) . '" "' . str_replace ( '\\' , '/' , $destination ) . '"' );
2006-08-25 15:15:53 +00:00
2005-03-21 23:10:11 +00:00
if ( file_exists ( $destination ))
2003-06-20 17:20:22 +00:00
{
2004-07-08 22:41:04 +00:00
$used_imagick = true ;
2003-06-20 17:20:22 +00:00
}
2006-05-12 20:52:58 +00:00
}
2003-06-20 17:20:22 +00:00
2007-10-05 14:30:11 +00:00
if ( ! $used_imagick )
2003-06-20 17:20:22 +00:00
{
2004-07-08 22:41:04 +00:00
$type = get_supported_image_types ( $type );
2006-05-12 20:52:58 +00:00
2004-07-08 22:41:04 +00:00
if ( $type [ 'gd' ])
2003-06-20 17:20:22 +00:00
{
2006-06-07 08:35:13 +00:00
// If the type is not supported, we are not able to create a thumbnail
if ( $type [ 'format' ] === false )
{
return false ;
}
2007-10-05 14:30:11 +00:00
switch ( $type [ 'format' ])
2003-06-20 17:20:22 +00:00
{
2004-07-08 22:41:04 +00:00
case IMG_GIF :
2006-06-07 08:35:13 +00:00
$image = @ imagecreatefromgif ( $source );
2006-05-12 20:52:58 +00:00
break ;
2004-07-08 22:41:04 +00:00
case IMG_JPG :
2009-08-01 12:13:16 +00:00
@ ini_set ( 'gd.jpeg_ignore_warning' , 1 );
2006-06-07 08:35:13 +00:00
$image = @ imagecreatefromjpeg ( $source );
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2004-07-08 22:41:04 +00:00
case IMG_PNG :
2006-06-07 08:35:13 +00:00
$image = @ imagecreatefrompng ( $source );
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2004-07-08 22:41:04 +00:00
case IMG_WBMP :
2006-06-07 08:35:13 +00:00
$image = @ imagecreatefromwbmp ( $source );
2006-05-12 20:52:58 +00:00
break ;
2004-07-08 22:41:04 +00:00
}
2009-07-31 15:49:14 +00:00
if ( empty ( $image ))
{
return false ;
}
2004-07-08 22:41:04 +00:00
if ( $type [ 'version' ] == 1 )
{
$new_image = imagecreate ( $new_width , $new_height );
2007-08-06 14:41:37 +00:00
if ( $new_image === false )
{
return false ;
}
2004-07-08 22:41:04 +00:00
imagecopyresized ( $new_image , $image , 0 , 0 , 0 , 0 , $new_width , $new_height , $width , $height );
}
else
{
$new_image = imagecreatetruecolor ( $new_width , $new_height );
2007-08-06 14:41:37 +00:00
if ( $new_image === false )
{
return false ;
}
2008-09-17 14:59:16 +00:00
// Preserve alpha transparency (png for example)
@ imagealphablending ( $new_image , false );
@ imagesavealpha ( $new_image , true );
2004-07-08 22:41:04 +00:00
imagecopyresampled ( $new_image , $image , 0 , 0 , 0 , 0 , $new_width , $new_height , $width , $height );
}
2006-06-06 20:53:46 +00:00
2006-08-03 15:23:34 +00:00
// If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
if ( @ ini_get ( 'safe_mode' ) || @ strtolower ( ini_get ( 'safe_mode' )) == 'on' )
{
@ touch ( $destination );
}
2004-07-08 22:41:04 +00:00
switch ( $type [ 'format' ])
{
case IMG_GIF :
2005-03-21 23:10:11 +00:00
imagegif ( $new_image , $destination );
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2004-07-08 22:41:04 +00:00
case IMG_JPG :
2005-03-21 23:10:11 +00:00
imagejpeg ( $new_image , $destination , 90 );
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2004-07-08 22:41:04 +00:00
case IMG_PNG :
2005-03-21 23:10:11 +00:00
imagepng ( $new_image , $destination );
2006-05-12 20:52:58 +00:00
break ;
2006-06-06 20:53:46 +00:00
2004-07-08 22:41:04 +00:00
case IMG_WBMP :
2005-03-21 23:10:11 +00:00
imagewbmp ( $new_image , $destination );
2006-05-12 20:52:58 +00:00
break ;
2003-06-20 17:20:22 +00:00
}
2004-07-08 22:41:04 +00:00
imagedestroy ( $new_image );
2003-06-20 17:20:22 +00:00
}
2006-06-07 08:35:13 +00:00
else
{
return false ;
}
2003-06-20 17:20:22 +00:00
}
2005-03-21 23:10:11 +00:00
if ( ! file_exists ( $destination ))
2003-06-20 17:20:22 +00:00
{
2004-01-25 14:30:15 +00:00
return false ;
2003-06-20 17:20:22 +00:00
}
2008-08-22 12:52:48 +00:00
phpbb_chmod ( $destination , CHMOD_READ | CHMOD_WRITE );
2003-11-16 21:53:56 +00:00
2004-01-25 14:30:15 +00:00
return true ;
2003-06-20 17:20:22 +00:00
}
2005-04-09 12:26:45 +00:00
/**
* Assign Inline attachments ( build option fields )
*/
2004-09-16 18:33:22 +00:00
function posting_gen_inline_attachments ( & $attachment_data )
2004-05-02 13:06:57 +00:00
{
global $template ;
2004-09-04 19:32:23 +00:00
if ( sizeof ( $attachment_data ))
2004-05-02 13:06:57 +00:00
{
$s_inline_attachment_options = '' ;
2006-06-06 20:53:46 +00:00
2004-09-04 19:32:23 +00:00
foreach ( $attachment_data as $i => $attachment )
2004-05-02 13:06:57 +00:00
{
2009-08-01 12:28:50 +00:00
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename ( $attachment [ 'real_filename' ]) . '</option>' ;
2004-05-02 13:06:57 +00:00
}
$template -> assign_var ( 'S_INLINE_ATTACHMENT_OPTIONS' , $s_inline_attachment_options );
return true ;
}
return false ;
}
2005-04-09 12:26:45 +00:00
/**
* Generate inline attachment entry
*/
2008-10-06 13:53:18 +00:00
function posting_gen_attachment_entry ( $attachment_data , & $filename_data , $show_attach_box = true )
2004-05-02 13:06:57 +00:00
{
2011-04-30 13:20:27 -04:00
global $template , $config , $phpbb_root_path , $phpEx , $user ;
2006-06-06 20:53:46 +00:00
2008-10-06 13:53:18 +00:00
// Some default template variables
2004-05-02 13:06:57 +00:00
$template -> assign_vars ( array (
2008-10-06 13:53:18 +00:00
'S_SHOW_ATTACH_BOX' => $show_attach_box ,
'S_HAS_ATTACHMENTS' => sizeof ( $attachment_data ),
'FILESIZE' => $config [ 'max_filesize' ],
'FILE_COMMENT' => ( isset ( $filename_data [ 'filecomment' ])) ? $filename_data [ 'filecomment' ] : '' ,
));
2004-05-02 13:06:57 +00:00
2004-09-04 19:32:23 +00:00
if ( sizeof ( $attachment_data ))
2004-05-02 13:06:57 +00:00
{
2006-11-21 18:15:53 +00:00
// We display the posted attachments within the desired order.
( $config [ 'display_order' ]) ? krsort ( $attachment_data ) : ksort ( $attachment_data );
foreach ( $attachment_data as $count => $attach_row )
2004-05-02 13:06:57 +00:00
{
$hidden = '' ;
2009-08-01 12:28:50 +00:00
$attach_row [ 'real_filename' ] = utf8_basename ( $attach_row [ 'real_filename' ]);
2004-05-02 13:06:57 +00:00
foreach ( $attach_row as $key => $value )
{
$hidden .= '<input type="hidden" name="attachment_data[' . $count . '][' . $key . ']" value="' . $value . '" />' ;
}
2006-06-06 20:53:46 +00:00
2007-10-02 18:29:05 +00:00
$download_link = append_sid ( " { $phpbb_root_path } download/file. $phpEx " , 'mode=view&id=' . ( int ) $attach_row [ 'attach_id' ], true , ( $attach_row [ 'is_orphan' ]) ? $user -> session_id : false );
2006-06-06 20:53:46 +00:00
2004-05-02 13:06:57 +00:00
$template -> assign_block_vars ( 'attach_row' , array (
2009-08-01 12:28:50 +00:00
'FILENAME' => utf8_basename ( $attach_row [ 'real_filename' ]),
'A_FILENAME' => addslashes ( utf8_basename ( $attach_row [ 'real_filename' ])),
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
'FILE_COMMENT' => $attach_row [ 'attach_comment' ],
2004-05-02 13:06:57 +00:00
'ATTACH_ID' => $attach_row [ 'attach_id' ],
2006-09-13 16:08:36 +00:00
'S_IS_ORPHAN' => $attach_row [ 'is_orphan' ],
2004-05-02 13:06:57 +00:00
'ASSOC_INDEX' => $count ,
2013-11-10 18:27:13 -08:00
'FILESIZE' => get_formatted_filesize ( $attach_row [ 'filesize' ]),
2004-05-02 13:06:57 +00:00
2006-05-12 20:52:58 +00:00
'U_VIEW_ATTACHMENT' => $download_link ,
2004-05-02 13:06:57 +00:00
'S_HIDDEN' => $hidden )
);
}
}
2004-09-04 19:32:23 +00:00
return sizeof ( $attachment_data );
2004-05-02 13:06:57 +00:00
}
2006-05-12 20:52:58 +00:00
//
// General Post functions
//
2005-04-09 12:26:45 +00:00
/**
* Load Drafts
*/
2009-06-26 11:38:29 +00:00
function load_drafts ( $topic_id = 0 , $forum_id = 0 , $id = 0 , $pm_action = '' , $msg_id = 0 )
2004-05-02 13:06:57 +00:00
{
2006-05-12 20:52:58 +00:00
global $user , $db , $template , $auth ;
2006-06-06 20:53:46 +00:00
global $phpbb_root_path , $phpEx ;
2006-05-12 20:52:58 +00:00
2006-05-20 18:39:35 +00:00
$topic_ids = $forum_ids = $draft_rows = array ();
2004-05-02 13:06:57 +00:00
2006-01-17 18:14:37 +00:00
// Load those drafts not connected to forums/topics
2006-05-17 16:58:56 +00:00
// If forum_id == 0 AND topic_id == 0 then this is a PM draft
2006-05-20 18:39:35 +00:00
if ( ! $topic_id && ! $forum_id )
{
2006-05-21 16:54:19 +00:00
$sql_and = ' AND d.forum_id = 0 AND d.topic_id = 0' ;
2006-05-20 18:39:35 +00:00
}
else
{
$sql_and = '' ;
2006-06-06 20:53:46 +00:00
$sql_and .= ( $forum_id ) ? ' AND d.forum_id = ' . ( int ) $forum_id : '' ;
$sql_and .= ( $topic_id ) ? ' AND d.topic_id = ' . ( int ) $topic_id : '' ;
2006-05-20 18:39:35 +00:00
}
$sql = ' SELECT d .* , f . forum_id , f . forum_name
FROM ' . DRAFTS_TABLE . ' d
LEFT JOIN ' . FORUMS_TABLE . ' f ON ( f . forum_id = d . forum_id )
WHERE d . user_id = ' . $user->data[' user_id ' ] . "
$sql_and
ORDER BY d . save_time DESC " ;
2004-05-02 13:06:57 +00:00
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
if ( $row [ 'topic_id' ])
{
$topic_ids [] = ( int ) $row [ 'topic_id' ];
}
2006-05-12 20:52:58 +00:00
$draft_rows [] = $row ;
2004-05-02 13:06:57 +00:00
}
$db -> sql_freeresult ( $result );
2006-01-17 18:14:37 +00:00
2006-05-12 20:52:58 +00:00
if ( ! sizeof ( $draft_rows ))
2006-01-17 18:14:37 +00:00
{
return ;
}
2006-05-12 20:52:58 +00:00
$topic_rows = array ();
2004-05-02 13:06:57 +00:00
if ( sizeof ( $topic_ids ))
{
$sql = ' SELECT topic_id , forum_id , topic_title
FROM ' . TOPICS_TABLE . '
2006-08-12 13:14:39 +00:00
WHERE ' . $db->sql_in_set(' topic_id ' , array_unique ( $topic_ids ));
2004-05-02 13:06:57 +00:00
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
$topic_rows [ $row [ 'topic_id' ]] = $row ;
}
$db -> sql_freeresult ( $result );
}
unset ( $topic_ids );
2006-05-20 18:39:35 +00:00
2006-01-17 18:14:37 +00:00
$template -> assign_var ( 'S_SHOW_DRAFTS' , true );
2006-05-12 20:52:58 +00:00
foreach ( $draft_rows as $draft )
2004-05-02 13:06:57 +00:00
{
2006-01-17 18:14:37 +00:00
$link_topic = $link_forum = $link_pm = false ;
$insert_url = $view_url = $title = '' ;
2004-05-02 13:06:57 +00:00
2007-05-17 13:01:17 +00:00
if ( isset ( $topic_rows [ $draft [ 'topic_id' ]])
&& (
( $topic_rows [ $draft [ 'topic_id' ]][ 'forum_id' ] && $auth -> acl_get ( 'f_read' , $topic_rows [ $draft [ 'topic_id' ]][ 'forum_id' ]))
||
( ! $topic_rows [ $draft [ 'topic_id' ]][ 'forum_id' ] && $auth -> acl_getf_global ( 'f_read' ))
))
2004-05-02 13:06:57 +00:00
{
2007-05-17 13:01:17 +00:00
$topic_forum_id = ( $topic_rows [ $draft [ 'topic_id' ]][ 'forum_id' ]) ? $topic_rows [ $draft [ 'topic_id' ]][ 'forum_id' ] : $forum_id ;
2006-01-17 18:14:37 +00:00
$link_topic = true ;
2007-05-17 13:01:17 +00:00
$view_url = append_sid ( " { $phpbb_root_path } viewtopic. $phpEx " , 'f=' . $topic_forum_id . '&t=' . $draft [ 'topic_id' ]);
2006-01-17 18:14:37 +00:00
$title = $topic_rows [ $draft [ 'topic_id' ]][ 'topic_title' ];
2004-05-02 13:06:57 +00:00
2007-05-17 13:01:17 +00:00
$insert_url = append_sid ( " { $phpbb_root_path } posting. $phpEx " , 'f=' . $topic_forum_id . '&t=' . $draft [ 'topic_id' ] . '&mode=reply&d=' . $draft [ 'draft_id' ]);
2006-01-17 18:14:37 +00:00
}
2006-05-17 16:58:56 +00:00
else if ( $draft [ 'forum_id' ] && $auth -> acl_get ( 'f_read' , $draft [ 'forum_id' ]))
2006-01-17 18:14:37 +00:00
{
$link_forum = true ;
2006-06-06 20:53:46 +00:00
$view_url = append_sid ( " { $phpbb_root_path } viewforum. $phpEx " , 'f=' . $draft [ 'forum_id' ]);
2006-01-17 18:14:37 +00:00
$title = $draft [ 'forum_name' ];
2004-05-02 13:06:57 +00:00
2006-06-06 20:53:46 +00:00
$insert_url = append_sid ( " { $phpbb_root_path } posting. $phpEx " , 'f=' . $draft [ 'forum_id' ] . '&mode=post&d=' . $draft [ 'draft_id' ]);
2006-01-17 18:14:37 +00:00
}
else
{
2006-05-17 16:58:56 +00:00
// Either display as PM draft if forum_id and topic_id are empty or if access to the forums has been denied afterwards...
2006-01-17 18:14:37 +00:00
$link_pm = true ;
2009-06-26 11:38:29 +00:00
$insert_url = append_sid ( " { $phpbb_root_path } ucp. $phpEx " , " i= $id &mode=compose&d= { $draft [ 'draft_id' ] } " . (( $pm_action ) ? " &action= $pm_action " : '' ) . (( $msg_id ) ? " &p= $msg_id " : '' ));
2004-05-02 13:06:57 +00:00
}
2006-05-12 20:52:58 +00:00
2006-01-17 18:14:37 +00:00
$template -> assign_block_vars ( 'draftrow' , array (
'DRAFT_ID' => $draft [ 'draft_id' ],
'DATE' => $user -> format_date ( $draft [ 'save_time' ]),
'DRAFT_SUBJECT' => $draft [ 'draft_subject' ],
'TITLE' => $title ,
'U_VIEW' => $view_url ,
'U_INSERT' => $insert_url ,
'S_LINK_PM' => $link_pm ,
'S_LINK_TOPIC' => $link_topic ,
'S_LINK_FORUM' => $link_forum )
);
2004-05-02 13:06:57 +00:00
}
}
2005-04-09 12:26:45 +00:00
/**
* Topic Review
*/
2004-07-11 15:20:35 +00:00
function topic_review ( $topic_id , $forum_id , $mode = 'topic_review' , $cur_post_id = 0 , $show_quote_button = true )
{
2007-05-19 12:04:22 +00:00
global $user , $auth , $db , $template , $bbcode , $cache ;
2013-07-11 14:24:07 +02:00
global $config , $phpbb_root_path , $phpEx , $phpbb_container ;
$phpbb_content_visibility = $phpbb_container -> get ( 'content.visibility' );
2004-07-11 15:20:35 +00:00
// Go ahead and pull all data for this topic
2007-02-13 23:20:34 +00:00
$sql = ' SELECT p . post_id
FROM ' . POSTS_TABLE . ' p ' . "
2004-07-11 15:20:35 +00:00
WHERE p . topic_id = $topic_id
2013-07-11 14:24:07 +02:00
AND " . $phpbb_content_visibility->get_visibility_sql ('post', $forum_id , 'p.') . '
2004-07-11 15:20:35 +00:00
' . (($mode == ' post_review ') ? " AND p.post_id > $cur_post_id" : ' ') . '
2009-07-08 10:22:36 +00:00
' . (($mode == ' post_review_edit ') ? " AND p.post_id = $cur_post_id" : ' ') . '
2008-01-30 18:48:03 +00:00
ORDER BY p . post_time ' ;
One commit for those fixes having a very tiny impact (mostly only whitespaces or forgotten spans, etc.)
Although i somehow mistakingly got #20445 and #15249 into it. :/
Removing s_watching_img from watch_topic_forum() function (Bug #20445)
Changing order for post review if more than one post affected (Bug #15249)
Language typos/fixes (Bug #20425, #15719, #15429, #14669, #13479)
Style/Template fixes (Bug #20065, #19405, #19205, #15028, #14934, #14821, #14752, #14497, #13707, #14738)
Tiny code fixes (Bug #20165, #20025, #19795, #14804)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8350 89ea8834-ac86-4346-8a33-228a782c2dd0
2008-01-30 16:01:15 +00:00
$sql .= ( $mode == 'post_review' ) ? 'ASC' : 'DESC' ;
2004-07-11 15:20:35 +00:00
$result = $db -> sql_query_limit ( $sql , $config [ 'posts_per_page' ]);
2007-02-13 23:20:34 +00:00
$post_list = array ();
while ( $row = $db -> sql_fetchrow ( $result ))
{
$post_list [] = $row [ 'post_id' ];
}
$db -> sql_freeresult ( $result );
if ( ! sizeof ( $post_list ))
2004-07-11 15:20:35 +00:00
{
return false ;
}
2009-07-08 10:22:36 +00:00
// Handle 'post_review_edit' like 'post_review' from now on
if ( $mode == 'post_review_edit' )
{
$mode = 'post_review' ;
}
2011-11-21 16:22:07 +01:00
$sql_ary = array (
2009-01-27 00:01:48 +00:00
'SELECT' => 'u.username, u.user_id, u.user_colour, p.*, z.friend, z.foe' ,
2007-02-13 23:20:34 +00:00
'FROM' => array (
USERS_TABLE => 'u' ,
POSTS_TABLE => 'p' ,
),
2009-01-27 00:01:48 +00:00
'LEFT_JOIN' => array (
array (
'FROM' => array ( ZEBRA_TABLE => 'z' ),
2011-11-21 16:22:07 +01:00
'ON' => 'z.user_id = ' . $user -> data [ 'user_id' ] . ' AND z.zebra_id = p.poster_id' ,
),
2009-01-27 00:01:48 +00:00
),
2007-02-13 23:20:34 +00:00
'WHERE' => $db -> sql_in_set ( 'p.post_id' , $post_list ) . '
2011-11-21 16:22:07 +01:00
AND u . user_id = p . poster_id ' ,
);
2007-02-13 23:20:34 +00:00
2011-11-21 16:22:07 +01:00
$sql = $db -> sql_build_query ( 'SELECT' , $sql_ary );
2007-02-13 23:20:34 +00:00
$result = $db -> sql_query ( $sql );
2006-07-24 10:08:36 +00:00
$bbcode_bitfield = '' ;
2007-02-13 23:22:42 +00:00
$rowset = array ();
2007-05-19 12:04:22 +00:00
$has_attachments = false ;
2007-02-13 23:20:34 +00:00
while ( $row = $db -> sql_fetchrow ( $result ))
2004-07-11 15:20:35 +00:00
{
2007-03-01 21:43:27 +00:00
$rowset [ $row [ 'post_id' ]] = $row ;
2006-08-11 21:52:46 +00:00
$bbcode_bitfield = $bbcode_bitfield | base64_decode ( $row [ 'bbcode_bitfield' ]);
2007-05-19 12:04:22 +00:00
if ( $row [ 'post_attachment' ])
{
$has_attachments = true ;
}
2004-07-11 15:20:35 +00:00
}
$db -> sql_freeresult ( $result );
// Instantiate BBCode class
2006-08-15 02:13:05 +00:00
if ( ! isset ( $bbcode ) && $bbcode_bitfield !== '' )
2004-07-11 15:20:35 +00:00
{
2006-06-06 20:53:46 +00:00
include_once ( $phpbb_root_path . 'includes/bbcode.' . $phpEx );
2006-08-15 02:13:05 +00:00
$bbcode = new bbcode ( base64_encode ( $bbcode_bitfield ));
2004-07-11 15:20:35 +00:00
}
2007-05-19 12:04:22 +00:00
// Grab extensions
$extensions = $attachments = array ();
if ( $has_attachments && $auth -> acl_get ( 'u_download' ) && $auth -> acl_get ( 'f_download' , $forum_id ))
{
$extensions = $cache -> obtain_attach_extensions ( $forum_id );
// Get attachments...
$sql = ' SELECT *
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $db->sql_in_set(' post_msg_id ', $post_list) . '
AND in_message = 0
ORDER BY filetime DESC , post_msg_id ASC ' ;
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
$attachments [ $row [ 'post_msg_id' ]][] = $row ;
}
$db -> sql_freeresult ( $result );
}
2007-03-01 21:43:27 +00:00
for ( $i = 0 , $end = sizeof ( $post_list ); $i < $end ; ++ $i )
2004-07-11 15:20:35 +00:00
{
2007-03-01 21:43:27 +00:00
// A non-existing rowset only happens if there was no user present for the entered poster_id
// This could be a broken posts table.
if ( ! isset ( $rowset [ $post_list [ $i ]]))
{
continue ;
}
2011-08-14 20:22:28 +02:00
$row = $rowset [ $post_list [ $i ]];
2007-03-01 21:43:27 +00:00
2006-11-16 16:51:19 +00:00
$poster_id = $row [ 'user_id' ];
$post_subject = $row [ 'post_subject' ];
2004-07-11 15:20:35 +00:00
2006-06-17 11:54:42 +00:00
$decoded_message = false ;
if ( $show_quote_button && $auth -> acl_get ( 'f_reply' , $forum_id ))
{
2013-08-03 21:46:06 +01:00
$decoded_message = censor_text ( $row [ 'post_text' ]);
2006-06-17 11:54:42 +00:00
decode_message ( $decoded_message , $row [ 'bbcode_uid' ]);
2007-08-19 13:40:53 +00:00
$decoded_message = bbcode_nl2br ( $decoded_message );
2006-06-17 11:54:42 +00:00
}
2004-07-11 15:20:35 +00:00
2013-07-15 20:06:54 +01:00
$parse_flags = ( $row [ 'bbcode_bitfield' ] ? OPTION_FLAG_BBCODE : 0 );
$parse_flags |= ( $row [ 'enable_smilies' ] ? OPTION_FLAG_SMILIES : 0 );
2013-08-03 21:46:06 +01:00
$message = generate_text_for_display ( $row [ 'post_text' ], $row [ 'bbcode_uid' ], $row [ 'bbcode_bitfield' ], $parse_flags , true );
2004-07-11 15:20:35 +00:00
2007-05-19 12:04:22 +00:00
if ( ! empty ( $attachments [ $row [ 'post_id' ]]))
{
$update_count = array ();
parse_attachments ( $forum_id , $message , $attachments [ $row [ 'post_id' ]], $update_count );
}
2004-07-11 15:20:35 +00:00
$post_subject = censor_text ( $post_subject );
2009-01-27 00:01:48 +00:00
$post_anchor = ( $mode == 'post_review' ) ? 'ppr' . $row [ 'post_id' ] : 'pr' . $row [ 'post_id' ];
$u_show_post = append_sid ( $phpbb_root_path . 'viewtopic.' . $phpEx , " f= $forum_id &t= $topic_id &p= { $row [ 'post_id' ] } &view=show#p { $row [ 'post_id' ] } " );
2004-07-11 15:20:35 +00:00
$template -> assign_block_vars ( $mode . '_row' , array (
2006-11-16 16:51:19 +00:00
'POST_AUTHOR_FULL' => get_username_string ( 'full' , $poster_id , $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
'POST_AUTHOR_COLOUR' => get_username_string ( 'colour' , $poster_id , $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
'POST_AUTHOR' => get_username_string ( 'username' , $poster_id , $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
'U_POST_AUTHOR' => get_username_string ( 'profile' , $poster_id , $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]),
2007-05-19 12:04:22 +00:00
'S_HAS_ATTACHMENTS' => ( ! empty ( $attachments [ $row [ 'post_id' ]])) ? true : false ,
2009-01-27 00:01:48 +00:00
'S_FRIEND' => ( $row [ 'friend' ]) ? true : false ,
'S_IGNORE_POST' => ( $row [ 'foe' ]) ? true : false ,
2014-04-07 21:42:30 +02:00
'L_IGNORE_POST' => ( $row [ 'foe' ]) ? sprintf ( $user -> lang [ 'POST_BY_FOE' ], get_username_string ( 'full' , $poster_id , $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ]), " <a href= \" { $u_show_post } \" onclick= \" phpbb.toggleDisplay(' { $post_anchor } ', 1); return false; \" > " , '</a>' ) : '' ,
2007-05-19 12:04:22 +00:00
2006-06-17 11:54:42 +00:00
'POST_SUBJECT' => $post_subject ,
2006-08-05 15:49:28 +00:00
'MINI_POST_IMG' => $user -> img ( 'icon_post_target' , $user -> lang [ 'POST' ]),
2006-06-17 11:54:42 +00:00
'POST_DATE' => $user -> format_date ( $row [ 'post_time' ]),
2006-08-28 17:20:21 +00:00
'MESSAGE' => $message ,
2006-06-17 11:54:42 +00:00
'DECODED_MESSAGE' => $decoded_message ,
2007-05-19 12:04:22 +00:00
'POST_ID' => $row [ 'post_id' ],
2006-06-17 11:54:42 +00:00
'U_MINI_POST' => append_sid ( " { $phpbb_root_path } viewtopic. $phpEx " , 'p=' . $row [ 'post_id' ]) . '#p' . $row [ 'post_id' ],
'U_MCP_DETAILS' => ( $auth -> acl_get ( 'm_info' , $forum_id )) ? append_sid ( " { $phpbb_root_path } mcp. $phpEx " , 'i=main&mode=post_details&f=' . $forum_id . '&p=' . $row [ 'post_id' ], true , $user -> session_id ) : '' ,
2006-11-17 19:40:21 +00:00
'POSTER_QUOTE' => ( $show_quote_button && $auth -> acl_get ( 'f_reply' , $forum_id )) ? addslashes ( get_username_string ( 'username' , $poster_id , $row [ 'username' ], $row [ 'user_colour' ], $row [ 'post_username' ])) : '' )
2004-07-11 15:20:35 +00:00
);
2007-05-19 12:04:22 +00:00
// Display not already displayed Attachments for this post, we already parsed them. ;)
if ( ! empty ( $attachments [ $row [ 'post_id' ]]))
{
foreach ( $attachments [ $row [ 'post_id' ]] as $attachment )
{
$template -> assign_block_vars ( $mode . '_row.attachment' , array (
'DISPLAY_ATTACHMENT' => $attachment )
);
}
}
2010-04-11 00:43:44 +02:00
unset ( $rowset [ $post_list [ $i ]]);
2004-07-11 15:20:35 +00:00
}
if ( $mode == 'topic_review' )
{
2006-08-05 15:49:28 +00:00
$template -> assign_var ( 'QUOTE_IMG' , $user -> img ( 'icon_post_quote' , $user -> lang [ 'REPLY_WITH_QUOTE' ]));
2004-07-11 15:20:35 +00:00
}
return true ;
}
2006-05-12 20:52:58 +00:00
//
// Post handling functions
//
/**
* Delete Post
*/
2012-09-28 16:53:38 +02:00
function delete_post ( $forum_id , $topic_id , $post_id , & $data , $is_soft = false , $softdelete_reason = '' )
2006-05-12 20:52:58 +00:00
{
2013-07-11 14:24:07 +02:00
global $db , $user , $auth , $phpbb_container ;
2006-06-06 20:53:46 +00:00
global $config , $phpEx , $phpbb_root_path ;
2006-05-12 20:52:58 +00:00
// Specify our post mode
2008-02-01 13:12:05 +00:00
$post_mode = 'delete' ;
2012-11-09 13:37:53 +01:00
if (( $data [ 'topic_first_post_id' ] === $data [ 'topic_last_post_id' ]) && ( $data [ 'topic_posts_approved' ] + $data [ 'topic_posts_unapproved' ] + $data [ 'topic_posts_softdeleted' ] == 1 ))
2008-02-01 13:12:05 +00:00
{
$post_mode = 'delete_topic' ;
}
2012-10-06 03:59:49 +02:00
else if ( $data [ 'topic_first_post_id' ] == $post_id )
2008-02-01 13:12:05 +00:00
{
$post_mode = 'delete_first_post' ;
2008-06-21 16:05:02 +00:00
}
2008-02-01 13:12:05 +00:00
else if ( $data [ 'topic_last_post_id' ] == $post_id )
{
$post_mode = 'delete_last_post' ;
}
2006-05-12 20:52:58 +00:00
$sql_data = array ();
2008-02-01 13:12:05 +00:00
$next_post_id = false ;
2006-05-12 20:52:58 +00:00
include_once ( $phpbb_root_path . 'includes/functions_admin.' . $phpEx );
2006-06-06 20:53:46 +00:00
$db -> sql_transaction ( 'begin' );
2006-05-12 20:52:58 +00:00
2007-07-04 14:22:15 +00:00
// we must make sure to update forums that contain the shadow'd topic
if ( $post_mode == 'delete_topic' )
{
$shadow_forum_ids = array ();
$sql = ' SELECT forum_id
FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set(' topic_moved_id ' , $topic_id );
$result = $db -> sql_query ( $sql );
while ( $row = $db -> sql_fetchrow ( $result ))
{
if ( ! isset ( $shadow_forum_ids [( int ) $row [ 'forum_id' ]]))
{
$shadow_forum_ids [( int ) $row [ 'forum_id' ]] = 1 ;
}
else
{
$shadow_forum_ids [( int ) $row [ 'forum_id' ]] ++ ;
}
}
$db -> sql_freeresult ( $result );
}
2013-07-11 14:24:07 +02:00
$phpbb_content_visibility = $phpbb_container -> get ( 'content.visibility' );
2012-10-06 03:59:49 +02:00
// (Soft) delete the post
2012-10-06 19:56:52 +02:00
if ( $is_soft && ( $post_mode != 'delete_topic' ))
2010-06-27 14:22:36 -05:00
{
2013-07-11 14:24:07 +02:00
$phpbb_content_visibility -> set_post_visibility ( ITEM_DELETED , $post_id , $topic_id , $forum_id , $user -> data [ 'user_id' ], time (), $softdelete_reason , ( $data [ 'topic_first_post_id' ] == $post_id ), ( $data [ 'topic_last_post_id' ] == $post_id ));
2010-06-27 14:22:36 -05:00
}
2012-10-06 19:56:52 +02:00
else if ( ! $is_soft )
2006-05-12 20:52:58 +00:00
{
2012-11-02 12:40:10 +01:00
if ( ! delete_posts ( 'post_id' , array ( $post_id ), false , false , false ))
2006-05-12 20:52:58 +00:00
{
2010-06-27 14:22:36 -05:00
// Try to delete topic, we may had an previous error causing inconsistency
if ( $post_mode == 'delete_topic' )
{
delete_topics ( 'topic_id' , array ( $topic_id ), false );
}
trigger_error ( 'ALREADY_DELETED' );
2006-05-12 20:52:58 +00:00
}
}
$db -> sql_transaction ( 'commit' );
2006-06-14 18:59:12 +00:00
// Collect the necessary information for updating the tables
2012-10-08 23:09:12 +02:00
$sql_data [ FORUMS_TABLE ] = $sql_data [ TOPICS_TABLE ] = '' ;
2006-05-12 20:52:58 +00:00
switch ( $post_mode )
{
case 'delete_topic' :
2007-07-04 14:22:15 +00:00
foreach ( $shadow_forum_ids as $updated_forum => $topic_count )
{
// counting is fun! we only have to do sizeof($forum_ids) number of queries,
// even if the topic is moved back to where its shadow lives (we count how many times it is in a forum)
2012-10-06 16:36:38 +02:00
$sql = 'UPDATE ' . FORUMS_TABLE . '
2012-11-10 11:24:52 +01:00
SET forum_topics_approved = forum_topics_approved - ' . $topic_count . '
2012-10-06 16:36:38 +02:00
WHERE forum_id = ' . $updated_forum ;
$db -> sql_query ( $sql );
2007-07-04 14:22:15 +00:00
update_post_information ( 'forum' , $updated_forum );
}
2010-06-27 14:22:36 -05:00
if ( $is_soft )
{
$topic_row = array ();
2013-07-11 14:24:07 +02:00
$phpbb_content_visibility -> set_topic_visibility ( ITEM_DELETED , $topic_id , $forum_id , $user -> data [ 'user_id' ], time (), $softdelete_reason );
2010-06-27 14:22:36 -05:00
}
else
{
delete_topics ( 'topic_id' , array ( $topic_id ), false );
2006-05-12 20:52:58 +00:00
2012-10-22 17:34:37 +02:00
if ( $data [ 'topic_visibility' ] == ITEM_APPROVED )
{
2012-11-10 11:24:52 +01:00
$sql_data [ FORUMS_TABLE ] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1' ;
2012-10-22 17:34:37 +02:00
}
2014-04-11 14:10:58 +02:00
else if ( $data [ 'topic_visibility' ] == ITEM_UNAPPROVED || $data [ 'post_visibility' ] == ITEM_REAPPROVE )
2012-10-22 17:34:37 +02:00
{
$sql_data [ FORUMS_TABLE ] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1' ;
}
else if ( $data [ 'topic_visibility' ] == ITEM_DELETED )
{
$sql_data [ FORUMS_TABLE ] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1' ;
}
2010-06-27 14:22:36 -05:00
$update_sql = update_post_information ( 'forum' , $forum_id , true );
if ( sizeof ( $update_sql ))
{
$sql_data [ FORUMS_TABLE ] .= ( $sql_data [ FORUMS_TABLE ]) ? ', ' : '' ;
$sql_data [ FORUMS_TABLE ] .= implode ( ', ' , $update_sql [ $forum_id ]);
}
2006-05-12 20:52:58 +00:00
}
2010-06-27 14:22:36 -05:00
2006-05-12 20:52:58 +00:00
break ;
case 'delete_first_post' :
2011-02-24 22:12:36 +00:00
$sql = ' SELECT p . post_id , p . poster_id , p . post_time , p . post_username , u . username , u . user_colour
2006-05-12 20:52:58 +00:00
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . " u
WHERE p . topic_id = $topic_id
AND p . poster_id = u . user_id
2012-10-06 16:36:38 +02:00
AND p . post_visibility = " . ITEM_APPROVED . '
ORDER BY p . post_time ASC ' ;
2006-05-12 20:52:58 +00:00
$result = $db -> sql_query_limit ( $sql , 1 );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2012-10-06 16:36:38 +02:00
if ( ! $row )
{
// No approved post, so the first is a not-approved post (unapproved or soft deleted)
$sql = ' SELECT p . post_id , p . poster_id , p . post_time , p . post_username , u . username , u . user_colour
FROM ' . POSTS_TABLE . ' p , ' . USERS_TABLE . " u
WHERE p . topic_id = $topic_id
AND p . poster_id = u . user_id
ORDER BY p . post_time ASC " ;
$result = $db -> sql_query_limit ( $sql , 1 );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
}
2006-05-12 20:52:58 +00:00
$next_post_id = ( int ) $row [ 'post_id' ];
2012-10-06 03:59:49 +02:00
$sql_data [ TOPICS_TABLE ] = $db -> sql_build_array ( 'UPDATE' , array (
'topic_poster' => ( int ) $row [ 'poster_id' ],
2012-10-06 16:36:38 +02:00
'topic_first_post_id' => ( int ) $row [ 'post_id' ],
2012-10-06 03:59:49 +02:00
'topic_first_poster_colour' => $row [ 'user_colour' ],
'topic_first_poster_name' => ( $row [ 'poster_id' ] == ANONYMOUS ) ? $row [ 'post_username' ] : $row [ 'username' ],
'topic_time' => ( int ) $row [ 'post_time' ],
));
2006-05-12 20:52:58 +00:00
break ;
case 'delete_last_post' :
2012-10-06 03:59:49 +02:00
if ( ! $is_soft )
2006-05-12 20:52:58 +00:00
{
2012-10-06 16:36:38 +02:00
// Update last post information when hard deleting. Soft delete already did that by itself.
2010-06-27 14:22:36 -05:00
$update_sql = update_post_information ( 'forum' , $forum_id , true );
if ( sizeof ( $update_sql ))
{
2012-10-06 16:36:38 +02:00
$sql_data [ FORUMS_TABLE ] = (( $sql_data [ FORUMS_TABLE ]) ? $sql_data [ FORUMS_TABLE ] . ', ' : '' ) . implode ( ', ' , $update_sql [ $forum_id ]);
2010-06-27 14:22:36 -05:00
}
2006-06-06 20:53:46 +00:00
2012-10-06 16:36:38 +02:00
$sql_data [ TOPICS_TABLE ] = (( $sql_data [ TOPICS_TABLE ]) ? $sql_data [ TOPICS_TABLE ] . ', ' : '' ) . 'topic_bumped = 0, topic_bumper = 0' ;
2006-05-12 20:52:58 +00:00
2012-10-06 03:59:49 +02:00
$update_sql = update_post_information ( 'topic' , $topic_id , true );
if ( ! empty ( $update_sql ))
{
$sql_data [ TOPICS_TABLE ] .= ', ' . implode ( ', ' , $update_sql [ $topic_id ]);
$next_post_id = ( int ) str_replace ( 'topic_last_post_id = ' , '' , $update_sql [ $topic_id ][ 0 ]);
}
2006-05-12 20:52:58 +00:00
}
2012-10-06 03:59:49 +02:00
if ( ! $next_post_id )
2006-05-12 20:52:58 +00:00
{
$sql = ' SELECT MAX ( post_id ) as last_post_id
FROM ' . POSTS_TABLE . "
2010-06-17 23:58:18 -05:00
WHERE topic_id = $topic_id
2013-07-11 14:24:07 +02:00
AND " . $phpbb_content_visibility->get_visibility_sql ('post', $forum_id );
2006-05-12 20:52:58 +00:00
$result = $db -> sql_query ( $sql );
2012-10-06 03:59:49 +02:00
$next_post_id = ( int ) $db -> sql_fetchfield ( 'last_post_id' );
2006-05-12 20:52:58 +00:00
$db -> sql_freeresult ( $result );
}
break ;
case 'delete' :
$sql = ' SELECT post_id
FROM ' . POSTS_TABLE . "
2010-06-17 23:58:18 -05:00
WHERE topic_id = $topic_id
2013-07-11 14:24:07 +02:00
AND " . $phpbb_content_visibility->get_visibility_sql ('post', $forum_id ) . '
2006-05-12 20:52:58 +00:00
AND post_time > ' . $data[' post_time '] . '
ORDER BY post_time ASC ' ;
$result = $db -> sql_query_limit ( $sql , 1 );
2012-10-06 03:59:49 +02:00
$next_post_id = ( int ) $db -> sql_fetchfield ( 'post_id' );
2006-05-12 20:52:58 +00:00
$db -> sql_freeresult ( $result );
2012-10-06 03:59:49 +02:00
break ;
}
2006-05-12 20:52:58 +00:00
2012-10-08 22:47:50 +02:00
if (( $post_mode == 'delete' ) || ( $post_mode == 'delete_last_post' ) || ( $post_mode == 'delete_first_post' ))
{
2012-10-06 03:59:49 +02:00
if ( ! $is_soft )
{
2012-10-08 22:47:50 +02:00
if ( $data [ 'post_visibility' ] == ITEM_APPROVED )
{
2013-07-11 14:24:07 +02:00
$phpbb_content_visibility -> remove_post_from_statistic ( $data , $sql_data );
2012-10-08 22:47:50 +02:00
}
2014-04-11 14:10:58 +02:00
else if ( $data [ 'post_visibility' ] == ITEM_UNAPPROVED || $data [ 'post_visibility' ] == ITEM_REAPPROVE )
2012-10-22 16:38:53 +02:00
{
$sql_data [ FORUMS_TABLE ] = (( $sql_data [ FORUMS_TABLE ]) ? $sql_data [ FORUMS_TABLE ] . ', ' : '' ) . 'forum_posts_unapproved = forum_posts_unapproved - 1' ;
$sql_data [ TOPICS_TABLE ] = (( $sql_data [ TOPICS_TABLE ]) ? $sql_data [ TOPICS_TABLE ] . ', ' : '' ) . 'topic_posts_unapproved = topic_posts_unapproved - 1' ;
}
else if ( $data [ 'post_visibility' ] == ITEM_DELETED )
{
2012-11-02 12:40:10 +01:00
$sql_data [ FORUMS_TABLE ] = (( $sql_data [ FORUMS_TABLE ]) ? $sql_data [ FORUMS_TABLE ] . ', ' : '' ) . 'forum_posts_softdeleted = forum_posts_softdeleted - 1' ;
$sql_data [ TOPICS_TABLE ] = (( $sql_data [ TOPICS_TABLE ]) ? $sql_data [ TOPICS_TABLE ] . ', ' : '' ) . 'topic_posts_softdeleted = topic_posts_softdeleted - 1' ;
2012-10-22 16:38:53 +02:00
}
2012-10-06 03:59:49 +02:00
}
2006-05-12 20:52:58 +00:00
2009-07-24 09:01:29 +00:00
$sql = ' SELECT 1 AS has_attachments
FROM ' . ATTACHMENTS_TABLE . '
2009-07-30 13:47:27 +00:00
WHERE topic_id = ' . $topic_id ;
$result = $db -> sql_query_limit ( $sql , 1 );
2009-07-24 09:01:29 +00:00
$has_attachments = ( int ) $db -> sql_fetchfield ( 'has_attachments' );
$db -> sql_freeresult ( $result );
if ( ! $has_attachments )
{
2012-10-08 22:47:50 +02:00
$sql_data [ TOPICS_TABLE ] = (( $sql_data [ TOPICS_TABLE ]) ? $sql_data [ TOPICS_TABLE ] . ', ' : '' ) . 'topic_attachment = 0' ;
2009-07-24 09:01:29 +00:00
}
}
2006-06-06 20:53:46 +00:00
$db -> sql_transaction ( 'begin' );
2006-05-12 20:52:58 +00:00
$where_sql = array (
FORUMS_TABLE => " forum_id = $forum_id " ,
TOPICS_TABLE => " topic_id = $topic_id " ,
2012-10-06 03:59:49 +02:00
USERS_TABLE => 'user_id = ' . $data [ 'poster_id' ],
2006-05-12 20:52:58 +00:00
);
foreach ( $sql_data as $table => $update_sql )
{
if ( $update_sql )
{
$db -> sql_query ( " UPDATE $table SET $update_sql WHERE " . $where_sql [ $table ]);
}
}
2006-05-27 16:24:21 +00:00
// Adjust posted info for this user by looking for a post by him/her within this topic...
2006-12-15 14:54:52 +00:00
if ( $post_mode != 'delete_topic' && $config [ 'load_db_track' ] && $data [ 'poster_id' ] != ANONYMOUS )
2006-05-27 16:24:21 +00:00
{
$sql = ' SELECT poster_id
FROM ' . POSTS_TABLE . '
WHERE topic_id = ' . $topic_id . '
2006-12-15 14:54:52 +00:00
AND poster_id = ' . $data[' poster_id ' ];
2006-05-27 16:24:21 +00:00
$result = $db -> sql_query_limit ( $sql , 1 );
$poster_id = ( int ) $db -> sql_fetchfield ( 'poster_id' );
$db -> sql_freeresult ( $result );
// The user is not having any more posts within this topic
if ( ! $poster_id )
{
$sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
WHERE topic_id = ' . $topic_id . '
2006-12-15 14:54:52 +00:00
AND user_id = ' . $data[' poster_id ' ];
2006-05-27 16:24:21 +00:00
$db -> sql_query ( $sql );
}
}
2007-05-05 10:22:24 +00:00
$db -> sql_transaction ( 'commit' );
2006-06-14 18:59:12 +00:00
if ( $data [ 'post_reported' ] && ( $post_mode != 'delete_topic' ))
{
sync ( 'topic_reported' , 'topic_id' , array ( $topic_id ));
}
2006-05-12 20:52:58 +00:00
return $next_post_id ;
}
/**
* Submit Post
2009-08-12 09:22:04 +00:00
* @ todo Split up and create lightweight , simple API for this .
2006-05-12 20:52:58 +00:00
*/
2009-08-12 09:22:04 +00:00
function submit_post ( $mode , $subject , $username , $topic_type , & $poll , & $data , $update_message = true , $update_search_index = true )
2006-05-12 20:52:58 +00:00
{
2013-12-08 15:08:30 -05:00
global $db , $auth , $user , $config , $phpEx , $template , $phpbb_root_path , $phpbb_container , $phpbb_dispatcher ;
2006-05-12 20:52:58 +00:00
2014-02-20 00:47:26 +08:00
/**
* Modify the data for post submitting
*
* @ event core . modify_submit_post_data
* @ var string mode Variable containing posting mode value
* @ var string subject Variable containing post subject value
* @ var string username Variable containing post author name
* @ var int topic_type Variable containing topic type value
* @ var array poll Array with the poll data for the post
* @ var array data Array with the data for the post
* @ var bool update_message Flag indicating if the post will be updated
* @ var bool update_search_index Flag indicating if the search index will be updated
* @ since 3.1 . 0 - a4
*/
2014-04-25 11:46:44 +02:00
$vars = array (
'mode' ,
'subject' ,
'username' ,
'topic_type' ,
'poll' ,
'data' ,
'update_message' ,
'update_search_index' ,
);
2014-04-17 16:33:12 +02:00
extract ( $phpbb_dispatcher -> trigger_event ( 'core.modify_submit_post_data' , compact ( $vars )));
2014-02-20 00:47:26 +08:00
2006-05-12 20:52:58 +00:00
// We do not handle erasing posts here
if ( $mode == 'delete' )
{
2006-05-26 15:04:27 +00:00
return false ;
2006-05-12 20:52:58 +00:00
}
$current_time = time ();
if ( $mode == 'post' )
{
$post_mode = 'post' ;
$update_message = true ;
}
else if ( $mode != 'edit' )
{
$post_mode = 'reply' ;
$update_message = true ;
}
else if ( $mode == 'edit' )
{
2012-11-09 13:37:53 +01:00
$post_mode = ( $data [ 'topic_posts_approved' ] + $data [ 'topic_posts_unapproved' ] + $data [ 'topic_posts_softdeleted' ] == 1 ) ? 'edit_topic' : (( $data [ 'topic_first_post_id' ] == $data [ 'post_id' ]) ? 'edit_first_post' : (( $data [ 'topic_last_post_id' ] == $data [ 'post_id' ]) ? 'edit_last_post' : 'edit' ));
2006-05-12 20:52:58 +00:00
}
2006-08-01 15:29:47 +00:00
// First of all make sure the subject and topic title are having the correct length.
2007-05-12 13:20:38 +00:00
// To achieve this without cutting off between special chars we convert to an array and then count the elements.
2012-05-02 13:13:20 +02:00
$subject = truncate_string ( $subject , 120 );
$data [ 'topic_title' ] = truncate_string ( $data [ 'topic_title' ], 120 );
2006-08-01 15:29:47 +00:00
2006-11-24 14:59:26 +00:00
// Collect some basic information about which tables and which rows to update/insert
2007-05-09 19:06:06 +00:00
$sql_data = $topic_row = array ();
2006-05-12 20:52:58 +00:00
$poster_id = ( $mode == 'edit' ) ? $data [ 'poster_id' ] : ( int ) $user -> data [ 'user_id' ];
2007-05-09 19:06:06 +00:00
// Retrieve some additional information if not present
2010-06-17 23:58:18 -05:00
if ( $mode == 'edit' && ( ! isset ( $data [ 'post_visibility' ]) || ! isset ( $data [ 'topic_visibility' ]) || $data [ 'post_visibility' ] === false || $data [ 'topic_visibility' ] === false ))
2007-05-09 19:06:06 +00:00
{
2012-11-10 11:24:52 +01:00
$sql = ' SELECT p . post_visibility , t . topic_type , t . topic_posts_approved , t . topic_posts_unapproved , t . topic_posts_softdeleted , t . topic_visibility
2007-05-09 19:06:06 +00:00
FROM ' . TOPICS_TABLE . ' t , ' . POSTS_TABLE . ' p
WHERE t . topic_id = p . topic_id
AND p . post_id = ' . $data[' post_id ' ];
$result = $db -> sql_query ( $sql );
$topic_row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2010-06-17 23:58:18 -05:00
$data [ 'topic_visibility' ] = $topic_row [ 'topic_visibility' ];
$data [ 'post_visibility' ] = $topic_row [ 'post_visibility' ];
2007-05-09 19:06:06 +00:00
}
2012-10-09 22:24:06 +02:00
// This variable indicates if the user is able to post or put into the queue
$post_visibility = ITEM_APPROVED ;
2008-09-02 06:36:24 +00:00
2012-05-22 02:20:21 +02:00
// Check the permissions for post approval.
// Moderators must go through post approval like ordinary users.
if ( ! $auth -> acl_get ( 'f_noapprove' , $data [ 'forum_id' ]))
2008-09-02 06:36:24 +00:00
{
2009-08-05 13:01:03 +00:00
// Post not approved, but in queue
2012-10-09 22:24:06 +02:00
$post_visibility = ITEM_UNAPPROVED ;
2014-04-11 14:10:58 +02:00
switch ( $post_mode )
{
case 'edit_first_post' :
case 'edit' :
case 'edit_last_post' :
case 'edit_topic' :
$post_visibility = ITEM_REAPPROVE ;
break ;
}
2008-09-02 06:36:24 +00:00
}
2012-10-09 22:24:06 +02:00
// MODs/Extensions are able to force any visibility on posts
2009-08-05 13:11:27 +00:00
if ( isset ( $data [ 'force_approved_state' ]))
2009-08-05 13:01:03 +00:00
{
2014-04-11 14:10:58 +02:00
$post_visibility = ( in_array (( int ) $data [ 'force_approved_state' ], array ( ITEM_APPROVED , ITEM_UNAPPROVED , ITEM_DELETED , ITEM_REAPPROVE ))) ? ( int ) $data [ 'force_approved_state' ] : $post_visibility ;
2012-10-09 22:24:06 +02:00
}
if ( isset ( $data [ 'force_visibility' ]))
{
2014-04-11 14:10:58 +02:00
$post_visibility = ( in_array (( int ) $data [ 'force_visibility' ], array ( ITEM_APPROVED , ITEM_UNAPPROVED , ITEM_DELETED , ITEM_REAPPROVE ))) ? ( int ) $data [ 'force_visibility' ] : $post_visibility ;
2009-08-05 13:01:03 +00:00
}
2007-05-09 21:42:24 +00:00
// Start the transaction here
$db -> sql_transaction ( 'begin' );
2006-11-24 14:59:26 +00:00
// Collect Information
2006-05-12 20:52:58 +00:00
switch ( $post_mode )
{
case 'post' :
case 'reply' :
$sql_data [ POSTS_TABLE ][ 'sql' ] = array (
2010-03-11 16:03:14 +01:00
'forum_id' => $data [ 'forum_id' ],
2006-06-06 20:53:46 +00:00
'poster_id' => ( int ) $user -> data [ 'user_id' ],
2006-05-12 20:52:58 +00:00
'icon_id' => $data [ 'icon_id' ],
2006-06-06 20:53:46 +00:00
'poster_ip' => $user -> ip ,
2006-05-12 20:52:58 +00:00
'post_time' => $current_time ,
2012-10-09 22:24:06 +02:00
'post_visibility' => $post_visibility ,
2006-06-06 20:53:46 +00:00
'enable_bbcode' => $data [ 'enable_bbcode' ],
'enable_smilies' => $data [ 'enable_smilies' ],
'enable_magic_url' => $data [ 'enable_urls' ],
'enable_sig' => $data [ 'enable_sig' ],
2006-05-12 20:52:58 +00:00
'post_username' => ( ! $user -> data [ 'is_registered' ]) ? $username : '' ,
'post_subject' => $subject ,
2006-06-06 20:53:46 +00:00
'post_text' => $data [ 'message' ],
2006-05-12 20:52:58 +00:00
'post_checksum' => $data [ 'message_md5' ],
2006-09-28 15:04:59 +00:00
'post_attachment' => ( ! empty ( $data [ 'attachment_data' ])) ? 1 : 0 ,
2006-05-12 20:52:58 +00:00
'bbcode_bitfield' => $data [ 'bbcode_bitfield' ],
'bbcode_uid' => $data [ 'bbcode_uid' ],
2006-08-02 09:36:31 +00:00
'post_postcount' => ( $auth -> acl_get ( 'f_postcount' , $data [ 'forum_id' ])) ? 1 : 0 ,
2006-05-12 20:52:58 +00:00
'post_edit_locked' => $data [ 'post_edit_locked' ]
);
break ;
case 'edit_first_post' :
case 'edit' :
2006-06-06 20:53:46 +00:00
2006-05-12 20:52:58 +00:00
case 'edit_last_post' :
case 'edit_topic' :
2007-05-02 16:19:35 +00:00
// If edit reason is given always display edit info
// If editing last post then display no edit info
// If m_edit permission then display no edit info
// If normal edit display edit info
// Display edit info if edit reason given or user is editing his post, which is not the last within the topic.
if ( $data [ 'post_edit_reason' ] || ( ! $auth -> acl_get ( 'm_edit' , $data [ 'forum_id' ]) && ( $post_mode == 'edit' || $post_mode == 'edit_first_post' )))
2006-05-12 20:52:58 +00:00
{
2008-06-21 16:05:02 +00:00
$data [ 'post_edit_reason' ] = truncate_string ( $data [ 'post_edit_reason' ], 255 , 255 , false );
2007-11-27 15:13:50 +00:00
2007-11-26 17:04:16 +00:00
$sql_data [ POSTS_TABLE ][ 'sql' ] = array (
2007-05-02 16:19:35 +00:00
'post_edit_time' => $current_time ,
'post_edit_reason' => $data [ 'post_edit_reason' ],
'post_edit_user' => ( int ) $data [ 'post_edit_user' ],
2006-05-12 20:52:58 +00:00
);
$sql_data [ POSTS_TABLE ][ 'stat' ][] = 'post_edit_count = post_edit_count + 1' ;
}
2007-09-02 17:24:56 +00:00
else if ( ! $data [ 'post_edit_reason' ] && $mode == 'edit' && $auth -> acl_get ( 'm_edit' , $data [ 'forum_id' ]))
{
$sql_data [ POSTS_TABLE ][ 'sql' ] = array (
'post_edit_reason' => '' ,
);
}
2006-05-12 20:52:58 +00:00
2007-05-06 21:02:23 +00:00
// If the person editing this post is different to the one having posted then we will add a log entry stating the edit
// Could be simplified by only adding to the log if the edit is not tracked - but this may confuse admins/mods
if ( $user -> data [ 'user_id' ] != $poster_id )
{
$log_subject = ( $subject ) ? $subject : $data [ 'topic_title' ];
2007-05-15 15:52:37 +00:00
add_log ( 'mod' , $data [ 'forum_id' ], $data [ 'topic_id' ], 'LOG_POST_EDITED' , $log_subject , ( ! empty ( $username )) ? $username : $user -> lang [ 'GUEST' ]);
2007-05-06 21:02:23 +00:00
}
2006-05-12 20:52:58 +00:00
if ( ! isset ( $sql_data [ POSTS_TABLE ][ 'sql' ]))
{
$sql_data [ POSTS_TABLE ][ 'sql' ] = array ();
}
$sql_data [ POSTS_TABLE ][ 'sql' ] = array_merge ( $sql_data [ POSTS_TABLE ][ 'sql' ], array (
2010-03-11 16:03:14 +01:00
'forum_id' => $data [ 'forum_id' ],
2006-06-06 20:53:46 +00:00
'poster_id' => $data [ 'poster_id' ],
2006-05-12 20:52:58 +00:00
'icon_id' => $data [ 'icon_id' ],
2012-10-09 22:24:06 +02:00
// We will change the visibility later
//'post_visibility' => $post_visibility,
2006-06-06 20:53:46 +00:00
'enable_bbcode' => $data [ 'enable_bbcode' ],
'enable_smilies' => $data [ 'enable_smilies' ],
'enable_magic_url' => $data [ 'enable_urls' ],
'enable_sig' => $data [ 'enable_sig' ],
2006-05-12 20:52:58 +00:00
'post_username' => ( $username && $data [ 'poster_id' ] == ANONYMOUS ) ? $username : '' ,
'post_subject' => $subject ,
'post_checksum' => $data [ 'message_md5' ],
2006-09-28 15:04:59 +00:00
'post_attachment' => ( ! empty ( $data [ 'attachment_data' ])) ? 1 : 0 ,
2006-05-12 20:52:58 +00:00
'bbcode_bitfield' => $data [ 'bbcode_bitfield' ],
'bbcode_uid' => $data [ 'bbcode_uid' ],
'post_edit_locked' => $data [ 'post_edit_locked' ])
);
if ( $update_message )
{
$sql_data [ POSTS_TABLE ][ 'sql' ][ 'post_text' ] = $data [ 'message' ];
}
break ;
}
2007-05-06 21:02:23 +00:00
$topic_row = array ();
2007-04-30 16:18:59 +00:00
2006-05-12 20:52:58 +00:00
// And the topic ladies and gentlemen
switch ( $post_mode )
{
case 'post' :
$sql_data [ TOPICS_TABLE ][ 'sql' ] = array (
'topic_poster' => ( int ) $user -> data [ 'user_id' ],
'topic_time' => $current_time ,
2009-04-08 16:18:58 +00:00
'topic_last_view_time' => $current_time ,
2010-03-11 16:03:14 +01:00
'forum_id' => $data [ 'forum_id' ],
2006-05-12 20:52:58 +00:00
'icon_id' => $data [ 'icon_id' ],
2012-11-09 13:37:53 +01:00
'topic_posts_approved' => ( $post_visibility == ITEM_APPROVED ) ? 1 : 0 ,
'topic_posts_softdeleted' => ( $post_visibility == ITEM_DELETED ) ? 1 : 0 ,
'topic_posts_unapproved' => ( $post_visibility == ITEM_UNAPPROVED ) ? 1 : 0 ,
2012-10-09 22:24:06 +02:00
'topic_visibility' => $post_visibility ,
2012-10-17 15:32:57 +02:00
'topic_delete_user' => ( $post_visibility != ITEM_APPROVED ) ? ( int ) $user -> data [ 'user_id' ] : 0 ,
2006-06-06 20:53:46 +00:00
'topic_title' => $subject ,
2006-05-12 20:52:58 +00:00
'topic_first_poster_name' => ( ! $user -> data [ 'is_registered' ] && $username ) ? $username : (( $user -> data [ 'user_id' ] != ANONYMOUS ) ? $user -> data [ 'username' ] : '' ),
2007-06-10 13:42:55 +00:00
'topic_first_poster_colour' => $user -> data [ 'user_colour' ],
2006-05-12 20:52:58 +00:00
'topic_type' => $topic_type ,
'topic_time_limit' => ( $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ) ? ( $data [ 'topic_time_limit' ] * 86400 ) : 0 ,
2006-09-28 15:04:59 +00:00
'topic_attachment' => ( ! empty ( $data [ 'attachment_data' ])) ? 1 : 0 ,
2006-05-12 20:52:58 +00:00
);
if ( isset ( $poll [ 'poll_options' ]) && ! empty ( $poll [ 'poll_options' ]))
{
2009-02-26 23:46:46 +00:00
$poll_start = ( $poll [ 'poll_start' ]) ? $poll [ 'poll_start' ] : $current_time ;
$poll_length = $poll [ 'poll_length' ] * 86400 ;
if ( $poll_length < 0 )
{
$poll_start = $poll_start + $poll_length ;
if ( $poll_start < 0 )
{
$poll_start = 0 ;
}
$poll_length = 1 ;
}
2006-05-12 20:52:58 +00:00
$sql_data [ TOPICS_TABLE ][ 'sql' ] = array_merge ( $sql_data [ TOPICS_TABLE ][ 'sql' ], array (
'poll_title' => $poll [ 'poll_title' ],
2009-02-26 23:46:46 +00:00
'poll_start' => $poll_start ,
2006-05-12 20:52:58 +00:00
'poll_max_options' => $poll [ 'poll_max_options' ],
2009-02-26 23:46:46 +00:00
'poll_length' => $poll_length ,
2006-05-12 20:52:58 +00:00
'poll_vote_change' => $poll [ 'poll_vote_change' ])
);
}
2012-10-09 22:24:06 +02:00
$sql_data [ USERS_TABLE ][ 'stat' ][] = " user_lastpost_time = $current_time " . (( $auth -> acl_get ( 'f_postcount' , $data [ 'forum_id' ]) && $post_visibility == ITEM_APPROVED ) ? ', user_posts = user_posts + 1' : '' );
One commit for those fixes having a very tiny impact (mostly only whitespaces or forgotten spans, etc.)
Although i somehow mistakingly got #20445 and #15249 into it. :/
Removing s_watching_img from watch_topic_forum() function (Bug #20445)
Changing order for post review if more than one post affected (Bug #15249)
Language typos/fixes (Bug #20425, #15719, #15429, #14669, #13479)
Style/Template fixes (Bug #20065, #19405, #19205, #15028, #14934, #14821, #14752, #14497, #13707, #14738)
Tiny code fixes (Bug #20165, #20025, #19795, #14804)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8350 89ea8834-ac86-4346-8a33-228a782c2dd0
2008-01-30 16:01:15 +00:00
2012-10-09 22:24:06 +02:00
if ( $post_visibility == ITEM_APPROVED )
2006-05-12 20:52:58 +00:00
{
2012-11-10 11:24:52 +01:00
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_topics_approved = forum_topics_approved + 1' ;
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_posts_approved = forum_posts_approved + 1' ;
2006-05-12 20:52:58 +00:00
}
2012-10-22 16:38:53 +02:00
else if ( $post_visibility == ITEM_UNAPPROVED )
{
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_topics_unapproved = forum_topics_unapproved + 1' ;
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_posts_unapproved = forum_posts_unapproved + 1' ;
}
else if ( $post_visibility == ITEM_DELETED )
{
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_topics_softdeleted = forum_topics_softdeleted + 1' ;
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1' ;
}
2006-05-12 20:52:58 +00:00
break ;
case 'reply' :
2009-04-08 16:18:58 +00:00
$sql_data [ TOPICS_TABLE ][ 'stat' ][] = 'topic_last_view_time = ' . $current_time . ' ,
topic_bumped = 0 ,
topic_bumper = 0 ' .
2012-11-10 11:24:52 +01:00
(( $post_visibility == ITEM_APPROVED ) ? ', topic_posts_approved = topic_posts_approved + 1' : '' ) .
2012-10-22 16:38:53 +02:00
(( $post_visibility == ITEM_UNAPPROVED ) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '' ) .
(( $post_visibility == ITEM_DELETED ) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '' ) .
2009-04-08 16:18:58 +00:00
(( ! empty ( $data [ 'attachment_data' ]) || ( isset ( $data [ 'topic_attachment' ]) && $data [ 'topic_attachment' ])) ? ', topic_attachment = 1' : '' );
2012-10-09 22:24:06 +02:00
$sql_data [ USERS_TABLE ][ 'stat' ][] = " user_lastpost_time = $current_time " . (( $auth -> acl_get ( 'f_postcount' , $data [ 'forum_id' ]) && $post_visibility == ITEM_APPROVED ) ? ', user_posts = user_posts + 1' : '' );
2006-05-12 20:52:58 +00:00
2012-10-09 22:24:06 +02:00
if ( $post_visibility == ITEM_APPROVED )
2006-05-12 20:52:58 +00:00
{
2012-11-10 11:24:52 +01:00
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_posts_approved = forum_posts_approved + 1' ;
2006-05-12 20:52:58 +00:00
}
2012-10-22 16:38:53 +02:00
else if ( $post_visibility == ITEM_UNAPPROVED )
{
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_posts_unapproved = forum_posts_unapproved + 1' ;
}
else if ( $post_visibility == ITEM_DELETED )
{
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1' ;
}
2006-05-12 20:52:58 +00:00
break ;
case 'edit_topic' :
case 'edit_first_post' :
2011-10-13 19:25:15 +02:00
if ( isset ( $poll [ 'poll_options' ]))
2009-02-26 23:46:46 +00:00
{
2011-10-13 19:25:15 +02:00
$poll_start = ( $poll [ 'poll_start' ] || empty ( $poll [ 'poll_options' ])) ? $poll [ 'poll_start' ] : $current_time ;
2009-02-26 23:46:46 +00:00
$poll_length = $poll [ 'poll_length' ] * 86400 ;
if ( $poll_length < 0 )
{
$poll_start = $poll_start + $poll_length ;
if ( $poll_start < 0 )
{
$poll_start = 0 ;
}
$poll_length = 1 ;
}
}
2006-05-12 20:52:58 +00:00
$sql_data [ TOPICS_TABLE ][ 'sql' ] = array (
2010-03-11 16:03:14 +01:00
'forum_id' => $data [ 'forum_id' ],
2006-05-12 20:52:58 +00:00
'icon_id' => $data [ 'icon_id' ],
2006-06-06 20:53:46 +00:00
'topic_title' => $subject ,
2006-05-12 20:52:58 +00:00
'topic_first_poster_name' => $username ,
'topic_type' => $topic_type ,
'topic_time_limit' => ( $topic_type == POST_STICKY || $topic_type == POST_ANNOUNCE ) ? ( $data [ 'topic_time_limit' ] * 86400 ) : 0 ,
'poll_title' => ( isset ( $poll [ 'poll_options' ])) ? $poll [ 'poll_title' ] : '' ,
2009-02-26 23:46:46 +00:00
'poll_start' => ( isset ( $poll [ 'poll_options' ])) ? $poll_start : 0 ,
2006-05-12 20:52:58 +00:00
'poll_max_options' => ( isset ( $poll [ 'poll_options' ])) ? $poll [ 'poll_max_options' ] : 1 ,
2009-02-26 23:46:46 +00:00
'poll_length' => ( isset ( $poll [ 'poll_options' ])) ? $poll_length : 0 ,
2006-05-12 20:52:58 +00:00
'poll_vote_change' => ( isset ( $poll [ 'poll_vote_change' ])) ? $poll [ 'poll_vote_change' ] : 0 ,
2009-04-08 16:18:58 +00:00
'topic_last_view_time' => $current_time ,
2006-05-12 20:52:58 +00:00
2006-09-28 15:04:59 +00:00
'topic_attachment' => ( ! empty ( $data [ 'attachment_data' ])) ? 1 : ( isset ( $data [ 'topic_attachment' ]) ? $data [ 'topic_attachment' ] : 0 ),
2006-05-12 20:52:58 +00:00
);
2007-03-08 15:49:13 +00:00
2006-05-12 20:52:58 +00:00
break ;
}
// Submit new topic
if ( $post_mode == 'post' )
{
$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' .
$db -> sql_build_array ( 'INSERT' , $sql_data [ TOPICS_TABLE ][ 'sql' ]);
$db -> sql_query ( $sql );
$data [ 'topic_id' ] = $db -> sql_nextid ();
$sql_data [ POSTS_TABLE ][ 'sql' ] = array_merge ( $sql_data [ POSTS_TABLE ][ 'sql' ], array (
'topic_id' => $data [ 'topic_id' ])
);
unset ( $sql_data [ TOPICS_TABLE ][ 'sql' ]);
}
// Submit new post
if ( $post_mode == 'post' || $post_mode == 'reply' )
{
if ( $post_mode == 'reply' )
{
$sql_data [ POSTS_TABLE ][ 'sql' ] = array_merge ( $sql_data [ POSTS_TABLE ][ 'sql' ], array (
2012-10-22 16:38:53 +02:00
'topic_id' => $data [ 'topic_id' ],
));
2006-05-12 20:52:58 +00:00
}
2007-01-11 05:44:22 +00:00
$sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db -> sql_build_array ( 'INSERT' , $sql_data [ POSTS_TABLE ][ 'sql' ]);
2006-05-12 20:52:58 +00:00
$db -> sql_query ( $sql );
$data [ 'post_id' ] = $db -> sql_nextid ();
2012-10-09 22:24:06 +02:00
if ( $post_mode == 'post' || $post_visibility == ITEM_APPROVED )
2006-05-12 20:52:58 +00:00
{
$sql_data [ TOPICS_TABLE ][ 'sql' ] = array (
2007-05-06 21:02:23 +00:00
'topic_last_post_id' => $data [ 'post_id' ],
'topic_last_post_time' => $current_time ,
2012-10-09 22:24:06 +02:00
'topic_last_poster_id' => $sql_data [ POSTS_TABLE ][ 'sql' ][ 'poster_id' ],
2012-11-02 12:40:10 +01:00
'topic_last_poster_name' => ( $user -> data [ 'user_id' ] == ANONYMOUS ) ? $sql_data [ POSTS_TABLE ][ 'sql' ][ 'post_username' ] : $user -> data [ 'username' ],
2007-06-10 13:42:55 +00:00
'topic_last_poster_colour' => $user -> data [ 'user_colour' ],
2008-06-09 12:35:10 +00:00
'topic_last_post_subject' => ( string ) $subject ,
2006-05-12 20:52:58 +00:00
);
}
2012-10-09 22:24:06 +02:00
if ( $post_mode == 'post' )
{
$sql_data [ TOPICS_TABLE ][ 'sql' ][ 'topic_first_post_id' ] = $data [ 'post_id' ];
}
// Update total post count and forum information
if ( $post_visibility == ITEM_APPROVED )
{
if ( $post_mode == 'post' )
{
set_config_count ( 'num_topics' , 1 , true );
}
set_config_count ( 'num_posts' , 1 , true );
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_last_post_id = ' . $data [ 'post_id' ];
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = " forum_last_post_subject = ' " . $db -> sql_escape ( $subject ) . " ' " ;
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_last_post_time = ' . $current_time ;
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = 'forum_last_poster_id = ' . ( int ) $user -> data [ 'user_id' ];
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = " forum_last_poster_name = ' " . $db -> sql_escape (( ! $user -> data [ 'is_registered' ] && $username ) ? $username : (( $user -> data [ 'user_id' ] != ANONYMOUS ) ? $user -> data [ 'username' ] : '' )) . " ' " ;
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = " forum_last_poster_colour = ' " . $db -> sql_escape ( $user -> data [ 'user_colour' ]) . " ' " ;
}
2006-05-12 20:52:58 +00:00
unset ( $sql_data [ POSTS_TABLE ][ 'sql' ]);
}
// Update the topics table
if ( isset ( $sql_data [ TOPICS_TABLE ][ 'sql' ]))
{
2006-06-06 20:53:46 +00:00
$sql = 'UPDATE ' . TOPICS_TABLE . '
2006-05-12 20:52:58 +00:00
SET ' . $db->sql_build_array(' UPDATE ', $sql_data[TOPICS_TABLE][' sql ']) . '
2006-06-06 20:53:46 +00:00
WHERE topic_id = ' . $data[' topic_id ' ];
$db -> sql_query ( $sql );
2012-10-09 22:24:06 +02:00
unset ( $sql_data [ TOPICS_TABLE ][ 'sql' ]);
2006-05-12 20:52:58 +00:00
}
// Update the posts table
if ( isset ( $sql_data [ POSTS_TABLE ][ 'sql' ]))
{
2006-06-06 20:53:46 +00:00
$sql = 'UPDATE ' . POSTS_TABLE . '
2006-08-06 05:52:41 +00:00
SET ' . $db->sql_build_array(' UPDATE ', $sql_data[POSTS_TABLE][' sql ']) . '
2006-06-06 20:53:46 +00:00
WHERE post_id = ' . $data[' post_id ' ];
$db -> sql_query ( $sql );
2012-10-09 22:24:06 +02:00
unset ( $sql_data [ POSTS_TABLE ][ 'sql' ]);
2006-05-12 20:52:58 +00:00
}
// Update Poll Tables
2011-10-13 19:25:15 +02:00
if ( isset ( $poll [ 'poll_options' ]))
2006-05-12 20:52:58 +00:00
{
$cur_poll_options = array ();
2011-10-13 19:25:15 +02:00
if ( $mode == 'edit' )
2006-05-12 20:52:58 +00:00
{
2007-04-02 16:05:48 +00:00
$sql = ' SELECT *
FROM ' . POLL_OPTIONS_TABLE . '
2006-05-12 20:52:58 +00:00
WHERE topic_id = ' . $data[' topic_id '] . '
ORDER BY poll_option_id ' ;
$result = $db -> sql_query ( $sql );
$cur_poll_options = array ();
while ( $row = $db -> sql_fetchrow ( $result ))
{
$cur_poll_options [] = $row ;
}
$db -> sql_freeresult ( $result );
}
$sql_insert_ary = array ();
One commit for those fixes having a very tiny impact (mostly only whitespaces or forgotten spans, etc.)
Although i somehow mistakingly got #20445 and #15249 into it. :/
Removing s_watching_img from watch_topic_forum() function (Bug #20445)
Changing order for post review if more than one post affected (Bug #15249)
Language typos/fixes (Bug #20425, #15719, #15429, #14669, #13479)
Style/Template fixes (Bug #20065, #19405, #19205, #15028, #14934, #14821, #14752, #14497, #13707, #14738)
Tiny code fixes (Bug #20165, #20025, #19795, #14804)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8350 89ea8834-ac86-4346-8a33-228a782c2dd0
2008-01-30 16:01:15 +00:00
2006-05-12 20:52:58 +00:00
for ( $i = 0 , $size = sizeof ( $poll [ 'poll_options' ]); $i < $size ; $i ++ )
{
2007-09-28 11:34:51 +00:00
if ( strlen ( trim ( $poll [ 'poll_options' ][ $i ])))
2006-05-12 20:52:58 +00:00
{
2006-05-21 16:54:19 +00:00
if ( empty ( $cur_poll_options [ $i ]))
2006-05-12 20:52:58 +00:00
{
2007-04-02 16:05:48 +00:00
// If we add options we need to put them to the end to be able to preserve votes...
2006-05-12 20:52:58 +00:00
$sql_insert_ary [] = array (
2007-04-02 16:05:48 +00:00
'poll_option_id' => ( int ) sizeof ( $cur_poll_options ) + 1 + sizeof ( $sql_insert_ary ),
2006-05-12 20:52:58 +00:00
'topic_id' => ( int ) $data [ 'topic_id' ],
'poll_option_text' => ( string ) $poll [ 'poll_options' ][ $i ]
);
}
else if ( $poll [ 'poll_options' ][ $i ] != $cur_poll_options [ $i ])
{
2007-04-02 16:05:48 +00:00
$sql = 'UPDATE ' . POLL_OPTIONS_TABLE . "
2006-05-12 20:52:58 +00:00
SET poll_option_text = '" . $db->sql_escape($poll[' poll_options '][$i]) . "'
2007-04-02 16:05:48 +00:00
WHERE poll_option_id = " . $cur_poll_options[$i] ['poll_option_id'] . '
AND topic_id = ' . $data[' topic_id ' ];
2006-05-12 20:52:58 +00:00
$db -> sql_query ( $sql );
}
}
}
2006-10-14 14:56:46 +00:00
$db -> sql_multi_insert ( POLL_OPTIONS_TABLE , $sql_insert_ary );
2006-05-12 20:52:58 +00:00
if ( sizeof ( $poll [ 'poll_options' ]) < sizeof ( $cur_poll_options ))
{
$sql = 'DELETE FROM ' . POLL_OPTIONS_TABLE . '
2007-09-28 11:34:51 +00:00
WHERE poll_option_id > ' . sizeof($poll[' poll_options ']) . '
2006-05-12 20:52:58 +00:00
AND topic_id = ' . $data[' topic_id ' ];
$db -> sql_query ( $sql );
}
2007-04-02 16:05:48 +00:00
// If edited, we would need to reset votes (since options can be re-ordered above, you can't be sure if the change is for changing the text or adding an option
if ( $mode == 'edit' && sizeof ( $poll [ 'poll_options' ]) != sizeof ( $cur_poll_options ))
{
$db -> sql_query ( 'DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . $data [ 'topic_id' ]);
$db -> sql_query ( 'UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = 0 WHERE topic_id = ' . $data [ 'topic_id' ]);
}
2006-05-12 20:52:58 +00:00
}
// Submit Attachments
2006-09-28 15:04:59 +00:00
if ( ! empty ( $data [ 'attachment_data' ]) && $data [ 'post_id' ] && in_array ( $mode , array ( 'post' , 'reply' , 'quote' , 'edit' )))
2006-05-12 20:52:58 +00:00
{
$space_taken = $files_added = 0 ;
2006-09-13 16:08:36 +00:00
$orphan_rows = array ();
2006-05-12 20:52:58 +00:00
foreach ( $data [ 'attachment_data' ] as $pos => $attach_row )
{
2006-09-13 16:08:36 +00:00
$orphan_rows [( int ) $attach_row [ 'attach_id' ]] = array ();
}
if ( sizeof ( $orphan_rows ))
{
$sql = ' SELECT attach_id , filesize , physical_filename
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $db->sql_in_set(' attach_id ', array_keys($orphan_rows)) . '
AND is_orphan = 1
AND poster_id = ' . $user->data[' user_id ' ];
$result = $db -> sql_query ( $sql );
$orphan_rows = array ();
while ( $row = $db -> sql_fetchrow ( $result ))
{
$orphan_rows [ $row [ 'attach_id' ]] = $row ;
}
$db -> sql_freeresult ( $result );
}
foreach ( $data [ 'attachment_data' ] as $pos => $attach_row )
{
One commit for those fixes having a very tiny impact (mostly only whitespaces or forgotten spans, etc.)
Although i somehow mistakingly got #20445 and #15249 into it. :/
Removing s_watching_img from watch_topic_forum() function (Bug #20445)
Changing order for post review if more than one post affected (Bug #15249)
Language typos/fixes (Bug #20425, #15719, #15429, #14669, #13479)
Style/Template fixes (Bug #20065, #19405, #19205, #15028, #14934, #14821, #14752, #14497, #13707, #14738)
Tiny code fixes (Bug #20165, #20025, #19795, #14804)
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8350 89ea8834-ac86-4346-8a33-228a782c2dd0
2008-01-30 16:01:15 +00:00
if ( $attach_row [ 'is_orphan' ] && ! isset ( $orphan_rows [ $attach_row [ 'attach_id' ]]))
2006-09-13 16:08:36 +00:00
{
continue ;
}
if ( ! $attach_row [ 'is_orphan' ])
2006-05-12 20:52:58 +00:00
{
// update entry in db if attachment already stored in db and filespace
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
SET attach_comment = '" . $db->sql_escape($attach_row[' attach_comment ']) . "'
2006-09-13 16:08:36 +00:00
WHERE attach_id = " . (int) $attach_row['attach_id'] . '
AND is_orphan = 0 ' ;
2006-05-12 20:52:58 +00:00
$db -> sql_query ( $sql );
}
else
{
// insert attachment into db
2009-08-01 12:28:50 +00:00
if ( !@ file_exists ( $phpbb_root_path . $config [ 'upload_path' ] . '/' . utf8_basename ( $orphan_rows [ $attach_row [ 'attach_id' ]][ 'physical_filename' ])))
2006-05-12 20:52:58 +00:00
{
continue ;
}
2006-06-06 20:53:46 +00:00
2006-09-13 16:08:36 +00:00
$space_taken += $orphan_rows [ $attach_row [ 'attach_id' ]][ 'filesize' ];
$files_added ++ ;
2006-05-12 20:52:58 +00:00
$attach_sql = array (
'post_msg_id' => $data [ 'post_id' ],
'topic_id' => $data [ 'topic_id' ],
2006-09-13 16:08:36 +00:00
'is_orphan' => 0 ,
2006-05-12 20:52:58 +00:00
'poster_id' => $poster_id ,
- renamed the following columns:
comment -> attach_comment
new, forwarded, unread, marked, deleted -> pm_new, pm_forwarded, pm_unread, pm_marked, pm_deleted
module_name -> module_basename
value -> lang_value
- every column is now NOT NULL
- every column is now having a DEFAULT value
- hopefully mostly consistent across every db schema
- untested schemas: sqlite, oracle, firebird
git-svn-id: file:///svn/phpbb/trunk@6177 89ea8834-ac86-4346-8a33-228a782c2dd0
2006-07-13 12:51:56 +00:00
'attach_comment' => $attach_row [ 'attach_comment' ],
2006-05-12 20:52:58 +00:00
);
2006-09-13 16:08:36 +00:00
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db -> sql_build_array ( 'UPDATE' , $attach_sql ) . '
WHERE attach_id = ' . $attach_row[' attach_id '] . '
AND is_orphan = 1
AND poster_id = ' . $user->data[' user_id ' ];
2006-05-12 20:52:58 +00:00
$db -> sql_query ( $sql );
}
}
2006-09-13 16:08:36 +00:00
if ( $space_taken && $files_added )
2006-05-12 20:52:58 +00:00
{
2009-03-19 17:01:59 +00:00
set_config_count ( 'upload_dir_size' , $space_taken , true );
set_config_count ( 'num_files' , $files_added , true );
2006-05-12 20:52:58 +00:00
}
}
2013-07-22 10:42:46 +02:00
$first_post_has_topic_info = ( $post_mode == 'edit_first_post' &&
(( $post_visibility == ITEM_DELETED && $data [ 'topic_posts_softdeleted' ] == 1 ) ||
( $post_visibility == ITEM_UNAPPROVED && $data [ 'topic_posts_unapproved' ] == 1 ) ||
2014-04-11 14:10:58 +02:00
( $post_visibility == ITEM_REAPPROVE && $data [ 'topic_posts_unapproved' ] == 1 ) ||
2013-07-22 10:42:46 +02:00
( $post_visibility == ITEM_APPROVED && $data [ 'topic_posts_approved' ] == 1 )));
2012-10-09 22:24:06 +02:00
// Fix the post's and topic's visibility and first/last post information, when the post is edited
if (( $post_mode != 'post' && $post_mode != 'reply' ) && $data [ 'post_visibility' ] != $post_visibility )
2006-05-12 20:52:58 +00:00
{
2012-10-09 22:24:06 +02:00
// If the post was not approved, it could also be the starter,
// so we sync the starter after approving/restoring, to ensure that the stats are correct
// Same applies for the last post
2014-04-13 21:09:07 +02:00
$is_starter = ( $post_mode == 'edit_first_post' || $post_mode == 'edit_topic' || $data [ 'post_visibility' ] != ITEM_APPROVED );
2012-10-09 22:24:06 +02:00
$is_latest = ( $post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data [ 'post_visibility' ] != ITEM_APPROVED );
2008-12-03 16:40:53 +00:00
2013-07-11 14:24:07 +02:00
$phpbb_content_visibility = $phpbb_container -> get ( 'content.visibility' );
$phpbb_content_visibility -> set_post_visibility ( $post_visibility , $data [ 'post_id' ], $data [ 'topic_id' ], $data [ 'forum_id' ], $user -> data [ 'user_id' ], time (), '' , $is_starter , $is_latest );
2007-05-09 02:19:31 +00:00
}
2013-07-22 10:42:46 +02:00
else if ( $post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $first_post_has_topic_info )
2006-05-12 20:52:58 +00:00
{
2012-10-09 22:24:06 +02:00
if ( $post_visibility == ITEM_APPROVED || $data [ 'topic_visibility' ] == $post_visibility )
2006-05-12 20:52:58 +00:00
{
2007-05-09 02:19:31 +00:00
// only the subject can be changed from edit
$sql_data [ TOPICS_TABLE ][ 'stat' ][] = " topic_last_post_subject = ' " . $db -> sql_escape ( $subject ) . " ' " ;
2008-12-03 16:40:53 +00:00
// Maybe not only the subject, but also changing anonymous usernames. ;)
if ( $data [ 'poster_id' ] == ANONYMOUS )
{
$sql_data [ TOPICS_TABLE ][ 'stat' ][] = " topic_last_poster_name = ' " . $db -> sql_escape ( $username ) . " ' " ;
}
2007-05-09 21:42:24 +00:00
2012-10-09 22:24:06 +02:00
if ( $post_visibility == ITEM_APPROVED )
{
// this does not _necessarily_ mean that we must update the info again,
// it just means that we might have to
$sql = ' SELECT forum_last_post_id , forum_last_post_subject
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . (int) $data[' forum_id ' ];
$result = $db -> sql_query ( $sql );
$row = $db -> sql_fetchrow ( $result );
$db -> sql_freeresult ( $result );
2006-05-12 20:52:58 +00:00
2012-10-09 22:24:06 +02:00
// this post is the latest post in the forum, better update
if ( $row [ 'forum_last_post_id' ] == $data [ 'post_id' ] && ( $row [ 'forum_last_post_subject' ] !== $subject || $data [ 'poster_id' ] == ANONYMOUS ))
{
// the post's subject changed
if ( $row [ 'forum_last_post_subject' ] !== $subject )
{
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = " forum_last_post_subject = ' " . $db -> sql_escape ( $subject ) . " ' " ;
}
2006-05-12 20:52:58 +00:00
2012-10-09 22:24:06 +02:00
// Update the user name if poster is anonymous... just in case a moderator changed it
if ( $data [ 'poster_id' ] == ANONYMOUS )
{
$sql_data [ FORUMS_TABLE ][ 'stat' ][] = " forum_last_poster_name = ' " . $db -> sql_escape ( $username ) . " ' " ;
}
}
}
2006-05-12 20:52:58 +00:00
}
}
// Update forum stats
2012-10-09 22:24:06 +02:00
$where_sql = array (
POSTS_TABLE => 'post_id = ' . $data [ 'post_id' ],
TOPICS_TABLE => 'topic_id = ' . $data [ 'topic_id' ],
FORUMS_TABLE => 'forum_id = ' . $data [ 'forum_id' ],
USERS_TABLE => 'user_id = ' . $poster_id
);
2006-05-12 20:52:58 +00:00
foreach ( $sql_data as $table => $update_ary )
{
if ( isset ( $update_ary [ 'stat' ]) && implode ( '' , $update_ary [ 'stat' ]))
{
2007-05-06 21:02:23 +00:00
$sql = " UPDATE $table SET " . implode ( ', ' , $update_ary [ 'stat' ]) . ' WHERE ' . $where_sql [ $table ];
$db -> sql_query ( $sql );
2006-05-12 20:52:58 +00:00
}
}
// Delete topic shadows (if any exist). We do not need a shadow topic for an global announcement
2010-03-11 16:03:14 +01:00
if ( $topic_type == POST_GLOBAL )
2006-05-12 20:52:58 +00:00
{
2006-06-06 20:53:46 +00:00
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
WHERE topic_moved_id = ' . $data[' topic_id ' ];
$db -> sql_query ( $sql );
2006-05-12 20:52:58 +00:00
}
2007-07-25 16:06:11 +00:00
// Committing the transaction before updating search index
$db -> sql_transaction ( 'commit' );
// Delete draft if post was loaded...
$draft_id = request_var ( 'draft_loaded' , 0 );
if ( $draft_id )
{
$sql = 'DELETE FROM ' . DRAFTS_TABLE . "
WHERE draft_id = $draft_id
AND user_id = { $user -> data [ 'user_id' ]} " ;
$db -> sql_query ( $sql );
}
2006-05-12 20:52:58 +00:00
// Index message contents
2009-08-12 09:22:04 +00:00
if ( $update_search_index && $data [ 'enable_indexing' ])
2006-05-12 20:52:58 +00:00
{
// Select the search method and do some additional checks to ensure it can actually be utilised
2011-08-15 20:00:47 -04:00
$search_type = $config [ 'search_type' ];
2006-06-06 20:53:46 +00:00
2007-07-03 15:36:18 +00:00
if ( ! class_exists ( $search_type ))
{
2011-08-15 20:00:47 -04:00
trigger_error ( 'NO_SUCH_SEARCH_MODULE' );
2007-07-03 15:36:18 +00:00
}
2006-05-12 20:52:58 +00:00
$error = false ;
2012-08-15 21:09:42 +05:30
$search = new $search_type ( $error , $phpbb_root_path , $phpEx , $auth , $config , $db , $user );
2006-06-06 20:53:46 +00:00
2006-05-12 20:52:58 +00:00
if ( $error )
{
trigger_error ( $error );
}
2010-03-11 16:03:14 +01:00
$search -> index ( $mode , $data [ 'post_id' ], $data [ 'message' ], $subject , $poster_id , $data [ 'forum_id' ]);
2006-05-12 20:52:58 +00:00
}
// Topic Notification, do not change if moderator is changing other users posts...
if ( $user -> data [ 'user_id' ] == $poster_id )
{
if ( ! $data [ 'notify_set' ] && $data [ 'notify' ])
{
$sql = 'INSERT INTO ' . TOPICS_WATCH_TABLE . ' ( user_id , topic_id )
VALUES ( ' . $user->data[' user_id '] . ' , ' . $data[' topic_id '] . ' ) ' ;
$db -> sql_query ( $sql );
}
2010-01-24 22:30:43 +00:00
else if (( $config [ 'email_enable' ] || $config [ 'jab_enable' ]) && $data [ 'notify_set' ] && ! $data [ 'notify' ])
2006-05-12 20:52:58 +00:00
{
$sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . '
WHERE user_id = ' . $user->data[' user_id '] . '
AND topic_id = ' . $data[' topic_id ' ];
$db -> sql_query ( $sql );
}
}
if ( $mode == 'post' || $mode == 'reply' || $mode == 'quote' )
{
// Mark this topic as posted to
2010-08-19 23:48:25 -04:00
markread ( 'post' , $data [ 'forum_id' ], $data [ 'topic_id' ]);
2006-05-12 20:52:58 +00:00
}
// Mark this topic as read
// We do not use post_time here, this is intended (post_time can have a date in the past if editing a message)
2010-03-11 16:03:14 +01:00
markread ( 'topic' , $data [ 'forum_id' ], $data [ 'topic_id' ], time ());
2006-05-12 20:52:58 +00:00
2006-08-09 21:03:46 +00:00
//
if ( $config [ 'load_db_lastread' ] && $user -> data [ 'is_registered' ])
{
$sql = ' SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data[' user_id '] . '
2010-03-11 16:03:14 +01:00
AND forum_id = ' . $data[' forum_id ' ];
2006-08-09 21:03:46 +00:00
$result = $db -> sql_query ( $sql );
$f_mark_time = ( int ) $db -> sql_fetchfield ( 'mark_time' );
$db -> sql_freeresult ( $result );
}
else if ( $config [ 'load_anon_lastread' ] || $user -> data [ 'is_registered' ])
{
$f_mark_time = false ;
}
2006-08-18 20:44:25 +00:00
if (( $config [ 'load_db_lastread' ] && $user -> data [ 'is_registered' ]) || $config [ 'load_anon_lastread' ] || $user -> data [ 'is_registered' ])
2006-08-09 21:03:46 +00:00
{
// Update forum info
2010-03-11 16:03:14 +01:00
$sql = ' SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $data[' forum_id ' ];
2006-08-09 21:03:46 +00:00
$result = $db -> sql_query ( $sql );
$forum_last_post_time = ( int ) $db -> sql_fetchfield ( 'forum_last_post_time' );
$db -> sql_freeresult ( $result );
2010-03-11 16:03:14 +01:00
update_forum_tracking_info ( $data [ 'forum_id' ], $forum_last_post_time , $f_mark_time , false );
2006-08-09 21:03:46 +00:00
}
2013-09-02 12:31:27 +02:00
// If a username was supplied or the poster is a guest, we will use the supplied username.
// Doing it this way we can use "...post by guest-username..." in notifications when
// "guest-username" is supplied or ommit the username if it is not.
$username = ( $username !== '' || ! $user -> data [ 'is_registered' ]) ? $username : $user -> data [ 'username' ];
2006-05-12 20:52:58 +00:00
// Send Notifications
2012-09-25 10:10:10 -05:00
$notification_data = array_merge ( $data , array (
'topic_title' => ( isset ( $data [ 'topic_title' ])) ? $data [ 'topic_title' ] : $subject ,
'post_username' => $username ,
'poster_id' => $poster_id ,
'post_text' => $data [ 'message' ],
'post_time' => $current_time ,
'post_subject' => $subject ,
));
2012-10-04 14:47:13 -05:00
2012-12-13 19:19:40 -06:00
$phpbb_notifications = $phpbb_container -> get ( 'notification_manager' );
2013-03-03 20:06:52 +01:00
if ( $post_visibility == ITEM_APPROVED )
2006-05-12 20:52:58 +00:00
{
2012-09-09 13:29:47 -05:00
switch ( $mode )
{
2012-10-14 12:42:18 -05:00
case 'post' :
2012-10-20 20:54:18 -05:00
$phpbb_notifications -> add_notifications ( array (
2012-11-20 18:14:48 -06:00
'quote' ,
'topic' ,
2012-10-20 20:54:18 -05:00
), $notification_data );
2012-09-09 14:55:40 -05:00
break ;
2012-10-14 12:42:18 -05:00
case 'reply' :
case 'quote' :
2012-10-20 20:54:18 -05:00
$phpbb_notifications -> add_notifications ( array (
2012-11-20 18:14:48 -06:00
'quote' ,
'bookmark' ,
'post' ,
2012-10-20 20:54:18 -05:00
), $notification_data );
2012-09-09 13:29:47 -05:00
break ;
2012-10-14 12:42:18 -05:00
case 'edit_topic' :
case 'edit_first_post' :
case 'edit' :
case 'edit_last_post' :
2012-10-20 20:54:18 -05:00
$phpbb_notifications -> update_notifications ( array (
2012-11-20 18:14:48 -06:00
'quote' ,
'bookmark' ,
'topic' ,
'post' ,
2012-10-20 20:54:18 -05:00
), $notification_data );
2012-09-09 13:29:47 -05:00
break ;
}
2006-05-12 20:52:58 +00:00
}
2013-03-06 16:29:50 +01:00
else if ( $post_visibility == ITEM_UNAPPROVED )
2012-09-15 14:33:15 -05:00
{
switch ( $mode )
{
2012-10-14 12:42:18 -05:00
case 'post' :
2012-11-20 18:14:48 -06:00
$phpbb_notifications -> add_notifications ( 'topic_in_queue' , $notification_data );
2012-09-15 14:33:15 -05:00
break ;
2012-10-14 12:42:18 -05:00
case 'reply' :
case 'quote' :
2012-11-20 18:14:48 -06:00
$phpbb_notifications -> add_notifications ( 'post_in_queue' , $notification_data );
2012-09-15 14:33:15 -05:00
break ;
2012-10-14 12:42:18 -05:00
case 'edit_topic' :
case 'edit_first_post' :
case 'edit' :
case 'edit_last_post' :
2014-04-11 12:28:14 +02:00
// Nothing to do here
2013-03-06 16:29:50 +01:00
break ;
}
}
2014-04-11 14:10:58 +02:00
else if ( $post_visibility == ITEM_REAPPROVE )
2013-03-06 16:29:50 +01:00
{
switch ( $mode )
{
2014-04-11 14:10:58 +02:00
case 'edit_topic' :
case 'edit_first_post' :
$phpbb_notifications -> add_notifications ( 'topic_in_queue' , $notification_data );
2014-04-19 11:14:01 +02:00
// Delete the approve_post notification so we can notify the user again,
// when his post got reapproved
$phpbb_notifications -> delete_notifications ( 'approve_post' , $notification_data [ 'post_id' ]);
2014-04-11 14:10:58 +02:00
break ;
case 'edit' :
case 'edit_last_post' :
$phpbb_notifications -> add_notifications ( 'post_in_queue' , $notification_data );
2014-04-19 11:14:01 +02:00
// Delete the approve_post notification so we can notify the user again,
// when his post got reapproved
$phpbb_notifications -> delete_notifications ( 'approve_post' , $notification_data [ 'post_id' ]);
2014-04-11 14:10:58 +02:00
break ;
2013-03-06 16:29:50 +01:00
case 'post' :
case 'reply' :
case 'quote' :
// Nothing to do here
break ;
2014-04-11 14:10:58 +02:00
}
}
2013-03-06 16:29:50 +01:00
else if ( $post_visibility == ITEM_DELETED )
{
switch ( $mode )
{
case 'post' :
case 'reply' :
case 'quote' :
case 'edit_topic' :
case 'edit_first_post' :
case 'edit' :
case 'edit_last_post' :
2014-04-11 12:28:14 +02:00
// Nothing to do here
2012-09-15 14:33:15 -05:00
break ;
}
2006-05-12 20:52:58 +00:00
}
2007-05-09 16:12:37 +00:00
$params = $add_anchor = '' ;
2007-05-06 21:02:23 +00:00
2012-10-09 22:24:06 +02:00
if ( $post_visibility == ITEM_APPROVED )
2006-05-12 20:52:58 +00:00
{
2007-05-06 21:02:23 +00:00
$params .= '&t=' . $data [ 'topic_id' ];
if ( $mode != 'post' )
{
$params .= '&p=' . $data [ 'post_id' ];
2007-05-07 02:35:12 +00:00
$add_anchor = '#p' . $data [ 'post_id' ];
2007-05-06 21:02:23 +00:00
}
2006-05-12 20:52:58 +00:00
}
2007-05-09 19:06:06 +00:00
else if ( $mode != 'post' && $post_mode != 'edit_first_post' && $post_mode != 'edit_topic' )
2006-05-12 20:52:58 +00:00
{
2007-05-06 21:02:23 +00:00
$params .= '&t=' . $data [ 'topic_id' ];
2006-05-12 20:52:58 +00:00
}
2007-05-09 16:12:37 +00:00
$url = ( ! $params ) ? " { $phpbb_root_path } viewforum. $phpEx " : " { $phpbb_root_path } viewtopic. $phpEx " ;
$url = append_sid ( $url , 'f=' . $data [ 'forum_id' ] . $params ) . $add_anchor ;
2007-05-06 21:02:23 +00:00
2013-12-08 14:42:46 -05:00
/**
* This event is used for performing actions directly after a post or topic
* has been submitted . When a new topic is posted , the topic ID is
* available in the $data array .
*
* The only action that can be done by altering data made available to this
2013-12-08 15:01:53 -05:00
* event is to modify the return URL ( $url ) .
2013-12-08 14:42:46 -05:00
*
* @ event core . submit_post_end
* @ var string url The " Return to topic " URL
* @ var array data Array of post data about the
* submitted post
2014-04-17 15:06:24 +02:00
* @ since 3.1 . 0 - a3
2013-12-08 14:42:46 -05:00
*/
$vars = array ( 'url' , 'data' );
extract ( $phpbb_dispatcher -> trigger_event ( 'core.submit_post_end' , compact ( $vars )));
2006-05-12 20:52:58 +00:00
return $url ;
}
2011-05-01 13:38:39 +08:00
/**
2010-10-18 21:25:52 +08:00
* Handle topic bumping
2011-05-01 13:38:39 +08:00
* @ param int $forum_id The ID of the forum the topic is being bumped belongs to
* @ param int $topic_id The ID of the topic is being bumping
* @ param array $post_data Passes some topic parameters :
* - 'topic_title'
* - 'topic_last_post_id'
* - 'topic_last_poster_id'
* - 'topic_last_post_subject'
* - 'topic_last_poster_name'
* - 'topic_last_poster_colour'
2011-06-10 00:26:41 +02:00
* @ param int $bump_time The time at which topic was bumped , usually it is a current time as obtained via time () .
2011-05-01 13:38:39 +08:00
* @ return string An URL to the bumped topic , example : ./ viewtopic . php ? forum_id = 1 & amptopic_id = 2 & ampp = 3 #p3
2010-10-18 21:25:52 +08:00
*/
2011-05-01 13:38:39 +08:00
function phpbb_bump_topic ( $forum_id , $topic_id , $post_data , $bump_time = false )
2010-10-18 21:25:52 +08:00
{
global $config , $db , $user , $phpEx , $phpbb_root_path ;
2011-05-01 13:38:39 +08:00
if ( $bump_time === false )
2010-10-18 21:25:52 +08:00
{
2011-05-01 13:38:39 +08:00
$bump_time = time ();
2010-10-18 21:25:52 +08:00
}
// Begin bumping
$db -> sql_transaction ( 'begin' );
// Update the topic's last post post_time
$sql = 'UPDATE ' . POSTS_TABLE . "
2011-05-01 13:38:39 +08:00
SET post_time = $bump_time
2010-10-18 21:25:52 +08:00
WHERE post_id = { $post_data [ 'topic_last_post_id' ]}
AND topic_id = $topic_id " ;
$db -> sql_query ( $sql );
// Sync the topic's last post time, the rest of the topic's last post data isn't changed
$sql = 'UPDATE ' . TOPICS_TABLE . "
2011-05-01 13:38:39 +08:00
SET topic_last_post_time = $bump_time ,
2010-10-18 21:25:52 +08:00
topic_bumped = 1 ,
topic_bumper = " . $user->data ['user_id'] . "
WHERE topic_id = $topic_id " ;
$db -> sql_query ( $sql );
// Update the forum's last post info
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET forum_last_post_id = " . $post_data['topic_last_post_id'] . " ,
forum_last_poster_id = " . $post_data['topic_last_poster_id'] . " ,
forum_last_post_subject = '" . $db->sql_escape($post_data[' topic_last_post_subject ']) . "' ,
2011-05-01 13:38:39 +08:00
forum_last_post_time = $bump_time ,
2010-10-18 21:25:52 +08:00
forum_last_poster_name = '" . $db->sql_escape($post_data[' topic_last_poster_name ']) . "' ,
forum_last_poster_colour = '" . $db->sql_escape($post_data[' topic_last_poster_colour ']) . "'
WHERE forum_id = $forum_id " ;
$db -> sql_query ( $sql );
// Update bumper's time of the last posting to prevent flood
$sql = 'UPDATE ' . USERS_TABLE . "
2011-05-01 13:38:39 +08:00
SET user_lastpost_time = $bump_time
2010-10-18 21:25:52 +08:00
WHERE user_id = " . $user->data ['user_id'];
$db -> sql_query ( $sql );
$db -> sql_transaction ( 'commit' );
// Mark this topic as posted to
2011-05-01 13:38:39 +08:00
markread ( 'post' , $forum_id , $topic_id , $bump_time );
2010-10-18 21:25:52 +08:00
// Mark this topic as read
2011-05-01 13:38:39 +08:00
markread ( 'topic' , $forum_id , $topic_id , $bump_time );
2010-10-18 21:25:52 +08:00
// Update forum tracking info
if ( $config [ 'load_db_lastread' ] && $user -> data [ 'is_registered' ])
{
$sql = ' SELECT mark_time
FROM ' . FORUMS_TRACK_TABLE . '
WHERE user_id = ' . $user->data[' user_id '] . '
AND forum_id = ' . $forum_id ;
$result = $db -> sql_query ( $sql );
$f_mark_time = ( int ) $db -> sql_fetchfield ( 'mark_time' );
$db -> sql_freeresult ( $result );
}
else if ( $config [ 'load_anon_lastread' ] || $user -> data [ 'is_registered' ])
{
$f_mark_time = false ;
}
if (( $config [ 'load_db_lastread' ] && $user -> data [ 'is_registered' ]) || $config [ 'load_anon_lastread' ] || $user -> data [ 'is_registered' ])
{
// Update forum info
$sql = ' SELECT forum_last_post_time
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $forum_id ;
$result = $db -> sql_query ( $sql );
$forum_last_post_time = ( int ) $db -> sql_fetchfield ( 'forum_last_post_time' );
$db -> sql_freeresult ( $result );
update_forum_tracking_info ( $forum_id , $forum_last_post_time , $f_mark_time , false );
}
add_log ( 'mod' , $forum_id , $topic_id , 'LOG_BUMP_TOPIC' , $post_data [ 'topic_title' ]);
$url = append_sid ( " { $phpbb_root_path } viewtopic. $phpEx " , " f= $forum_id &t= $topic_id &p= { $post_data [ 'topic_last_post_id' ] } " ) . " #p { $post_data [ 'topic_last_post_id' ] } " ;
return $url ;
}