Skip to content

Instantly share code, notes, and snippets.

@marc1706
Created April 10, 2012 16:34
Show Gist options
  • Save marc1706/2352689 to your computer and use it in GitHub Desktop.
Save marc1706/2352689 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
// <![CDATA[
var pjb = jQuery.noConflict(); // just so you know what pjb is used for
pjb(document).ready(function(){
// quickedit -- .qe-icon is the class of the quickedit button
pjb('.qe-icon a').click(function() {
post_id = pjb(this).attr('id');
// there are obviously better ways to do this
post_id = post_id.replace(/quickedit/g, ''); // filter out the post ID
// check if quick edit is already enabled -- don't allow more than one open quickedit
if(popup_open != true)
{
// this is needed in global announcements as far as I remember
cur_location = pjb(location).attr('href');
data = 'mode=quickedit&qe_mode=init&post_id=' + post_id + '&location=' + location;
// obviously the ajax call -- true just tells the function that it should expect a JSON reply
// it will call function open_edit() afterwards
pjB_do_ajax('open', data, true);
popup_open = true;
cur_post_id = post_id;
}
});
});
// open edit window
function open_edit(success)
{
if(success['ERROR'])
{
for(i = 0; i < success['ERROR_COUNT']; i++)
{
pjB_output_info('', success['ERROR'][i], true);
}
}
else
{
pjb('#post' + cur_post_id + ' div.content').hide();
pjb('#post' + cur_post_id + ' div.notice').hide();
pjb('#post' + cur_post_id + ' dl.attachbox').hide();
// the column 'TPL_BODY' will hold the returned HTML for the quickedit
pjb('#post' + cur_post_id).append(success['TPL_BODY']);
pjb('#pjB-qe-form').show('slow');
// bind_quickedit_buttons is needed for the bbcode buttons as well as "submit", "cancel", and "advanced edit"
bind_quickedit_buttons();
quickedit_open = true;
}
}
/*
* Onclick functions for BBCode buttons
*/
function bind_quickedit_buttons()
{
// somebody clicks on the bbcode buttons
pjb('#quickedit-buttons input').bind('click', function() {
cur_bbcode = pjb(this).attr('id');
cur_bbcode = cur_bbcode.replace(/bbcode/g, ''); // filter out unneeded parts
// make sure we don't get javascript errors
if (cur_bbcode == parseInt(cur_bbcode))
{
// same as bbstyle()
qe_bbstyle(parseInt(cur_bbcode));
}
});
// somebody uses the size dropdown box
pjb('select#addbbcode202').bind('change', function() {
var cur_size = pjb('select#addbbcode202 option:selected').val();
// same as bbfontstyle()
qe_bbfontstyle('[size=' + cur_size + ']', '[/size]');
pjb('select#addbbcode202 option')[2].attr('selected', 'selected');
});
// click on "submit"
pjb('#submit_jqe').bind('click', function() {
if(quickedit_open == true)
{
content = pjb('textarea#jqe-message').serialize();
content = content.substring(8); // make sure we get rid of the 'message=' in front of the post text
cur_location = pjb(location).attr('href');
data = 'mode=quickedit&qe_mode=submit&post_id=' + post_id + '&contents=' + content + '&location=' + location;
pjB_do_ajax('submit', data, true);
}
});
// click on "cancel"
pjb('#cancel_jqe').bind('click', function() {
if(quickedit_open == true)
{
pjb('textarea#jqe-message').val(''); // make sure the user can't see what was in the textbox after clicking cancel
cancel_edit(); // we don't need an ajax request since we just need to close the edit window
quickedit_open = false;
}
});
// click on "advanced edit"
pjb('#adv_jqe').bind('mouseover', function() {
if(quickedit_open == true)
{
// get current url for forum_id if we have a global announcement
content = pjb('textarea#jqe-message').val();
pjb('input[name="message"]:hidden').val(content);
}
});
}
// submit edit
function submit_edit(data)
{
if(data['ERROR'])
{
for(i = 0; i < data['ERROR_COUNT']; i++)
{
pjB_output_info('', data['ERROR'][i], true);
}
if(data['ERROR_ACTION'] == 'cancel')
{
cancel_edit();
}
}
else
{
pjb('#post' + cur_post_id + ' div.content').html(data['TEXT']);
pjb('#post' + cur_post_id + ' div.notice').html(data['EDITED_BY']);
pjb('#pjB-qe-form').hide('slow');
pjb('#pjB-qe-form').remove();
pjb('#post' + cur_post_id + ' div.content').show('slow');
pjb('#post' + cur_post_id + ' dl.attachbox').show('slow');
pjb('#post' + cur_post_id + ' div.notice').show('slow');
<!-- IF PJB_POPUPS_ENABLE -->
pjB_output_info(data['SUCCESS_TITLE'], data['SUCCESS_MESSAGE'], true);
<!-- ENDIF -->
quickedit_open = false;
popup_open = false;
}
}
// cancel quickedit
function cancel_edit()
{
pjb('#pjB-qe-form').hide('slow');
pjb('#pjB-qe-form').remove();
pjb('#post' + cur_post_id + ' div.content').show('slow');
pjb('#post' + cur_post_id + ' dl.attachbox').show('slow');
pjb('#post' + cur_post_id + ' div.notice').show('slow');
quickedit_open = false;
popup_open = false;
}
// ]]>
</script>
<script type="text/javascript">
// <![CDATA[
var pjb = jQuery.noConflict(); // just so you know what pjb is used for
pjb(document).ready(function(){
// quickedit -- .qe-icon is the class of the quickedit button
pjb('.qe-icon a').click(function() {
post_id = pjb(this).attr('id');
// there are obviously better ways to do this
post_id = post_id.replace(/quickedit/g, ''); // filter out the post ID
// check if quick edit is already enabled -- don't allow more than one open quickedit
if(popup_open != true)
{
// this is needed in global announcements as far as I remember
cur_location = pjb(location).attr('href');
data = 'mode=quickedit&qe_mode=init&post_id=' + post_id + '&location=' + location;
// obviously the ajax call -- true just tells the function that it should expect a JSON reply
// it will call function open_edit() afterwards
pjB_do_ajax('open', data, true);
popup_open = true;
cur_post_id = post_id;
}
});
});
// open edit window
function open_edit(success)
{
if(success['ERROR'])
{
for(i = 0; i < success['ERROR_COUNT']; i++)
{
pjB_output_info('', success['ERROR'][i], true);
}
}
else
{
pjb('#post' + cur_post_id + ' div.content').hide();
pjb('#post' + cur_post_id + ' div.notice').hide();
pjb('#post' + cur_post_id + ' dl.attachbox').hide();
// the column 'TPL_BODY' will hold the returned HTML for the quickedit
pjb('#post' + cur_post_id).append(success['TPL_BODY']);
pjb('#pjB-qe-form').show('slow');
// bind_quickedit_buttons is needed for the bbcode buttons as well as "submit", "cancel", and "advanced edit"
bind_quickedit_buttons();
quickedit_open = true;
}
}
/*
* Onclick functions for BBCode buttons
*/
function bind_quickedit_buttons()
{
// somebody clicks on the bbcode buttons
pjb('#quickedit-buttons input').bind('click', function() {
cur_bbcode = pjb(this).attr('id');
cur_bbcode = cur_bbcode.replace(/bbcode/g, ''); // filter out unneeded parts
// make sure we don't get javascript errors
if (cur_bbcode == parseInt(cur_bbcode))
{
// same as bbstyle()
qe_bbstyle(parseInt(cur_bbcode));
}
});
// somebody uses the size dropdown box
pjb('select#addbbcode202').bind('change', function() {
var cur_size = pjb('select#addbbcode202 option:selected').val();
// same as bbfontstyle()
qe_bbfontstyle('[size=' + cur_size + ']', '[/size]');
pjb('select#addbbcode202 option')[2].attr('selected', 'selected');
});
// click on "submit"
pjb('#submit_jqe').bind('click', function() {
if(quickedit_open == true)
{
content = pjb('textarea#jqe-message').serialize();
content = content.substring(8); // make sure we get rid of the 'message=' in front of the post text
cur_location = pjb(location).attr('href');
data = 'mode=quickedit&qe_mode=submit&post_id=' + post_id + '&contents=' + content + '&location=' + location;
pjB_do_ajax('submit', data, true);
}
});
// click on "cancel"
pjb('#cancel_jqe').bind('click', function() {
if(quickedit_open == true)
{
pjb('textarea#jqe-message').val(''); // make sure the user can't see what was in the textbox after clicking cancel
cancel_edit(); // we don't need an ajax request since we just need to close the edit window
quickedit_open = false;
}
});
// click on "advanced edit"
pjb('#adv_jqe').bind('mouseover', function() {
if(quickedit_open == true)
{
// get current url for forum_id if we have a global announcement
content = pjb('textarea#jqe-message').val();
pjb('input[name="message"]:hidden').val(content);
}
});
}
// submit edit
function submit_edit(data)
{
if(data['ERROR'])
{
for(i = 0; i < data['ERROR_COUNT']; i++)
{
pjB_output_info('', data['ERROR'][i], true);
}
if(data['ERROR_ACTION'] == 'cancel')
{
cancel_edit();
}
}
else
{
pjb('#post' + cur_post_id + ' div.content').html(data['TEXT']);
pjb('#post' + cur_post_id + ' div.notice').html(data['EDITED_BY']);
pjb('#pjB-qe-form').hide('slow');
pjb('#pjB-qe-form').remove();
pjb('#post' + cur_post_id + ' div.content').show('slow');
pjb('#post' + cur_post_id + ' dl.attachbox').show('slow');
pjb('#post' + cur_post_id + ' div.notice').show('slow');
<!-- IF PJB_POPUPS_ENABLE -->
pjB_output_info(data['SUCCESS_TITLE'], data['SUCCESS_MESSAGE'], true);
<!-- ENDIF -->
quickedit_open = false;
popup_open = false;
}
}
// cancel quickedit
function cancel_edit()
{
pjb('#pjB-qe-form').hide('slow');
pjb('#pjB-qe-form').remove();
pjb('#post' + cur_post_id + ' div.content').show('slow');
pjb('#post' + cur_post_id + ' dl.attachbox').show('slow');
pjb('#post' + cur_post_id + ' div.notice').show('slow');
quickedit_open = false;
popup_open = false;
}
<?php
/**
*
* @package phpBB jQuery Base
* @copyright (c) 2012 Marc Alexander(marc1706) www.m-a-styles.de
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if(!defined('IN_PHPBB') || !defined('IN_JQUERY_BASE'))
{
exit;
}
class phpbb_jquery_base
{
/*
* initial vars
*/
private $error = array(); // save errors in here (i.e. when quickediting posts)
private $mode;
private $post_id;
private $location;
private $forum_id;
private $submit = false;
private $load_tpl = false;
private $return = array();
private $tpl_file;
private $return_ary = array();
public $config = array();
/*
* function definitions below
*/
/*
* initialise variables for following actions
*/
public function __construct()
{
global $user, $phpbb_root_path, $phpEx, $auth, $config;
$this->post_id = request_var('post_id', 0);
$this->mode = request_var('mode', '');
$this->location = request_var('location', '');
$this->submit = request_var('submit', false);
$this->obtain_config();
$set_no_auth = false;
// provide a valid location (need for some functions)
$this->location = utf8_normalize_nfc(request_var('location', '', true));
$this->forum_id = strstr($this->location, 'f=');
$first_loc = strpos($this->forum_id, '&');
$this->forum_id = ($first_loc) ? substr($this->forum_id, 2, $first_loc) : substr($this->forum_id, 2);
$this->forum_id = (int) $this->forum_id; // make sure it's an int
/*
* if somebody previews a style using the style URL parameter, we need to do this
* this will not work for other cases
*/
if ($this->forum_id < 1)
{
$this->forum_id = request_var('f', 0);
}
// include needed files
switch ($this->mode)
{
case 'quickedit':
// do nothing if quickedit is disabled
if ($config['pjb_quickedit_enable'])
{
if ($auth->acl_get('u_quickedit'))
{
$this->include_file('includes/functions_display', 'display_forums');
$this->include_file('includes/message_parser', 'bbcode_firstpass', true);
}
else
{
$set_no_auth = true;
}
}
break;
default:
$this->error[] = array('error' => 'NO_MODE', 'action' => 'cancel');
}
if ($set_no_auth == true)
{
$this->error[] = array('error' => 'NO_AUTH_OPERATION', 'action' => 'cancel');
}
}
/*
* Get config data from $config
* We just use the cached array $config
*
* __construct() will run this function
*/
private function obtain_config()
{
global $config;
foreach($config as $key => $value)
{
$jquery_config_name = 'pjb_'; // all config variables of phpBB jQuery Base start with this
$cur_pos = strpos($key, $jquery_config_name);
if($cur_pos !== false)
{
$this->config[$key] = $value;
}
}
}
/*
* Run actions for the specified mode
*
* @param: none
*/
public function run_actions()
{
global $config, $auth;
// don't do anything if we already have an error because it can only be a "NO_MODE" error
if(empty($error))
{
switch($this->mode)
{
case 'quickedit':
if ($config['pjb_quickedit_enable'] && $auth->acl_get('u_quickedit'))
{
$this->quickedit();
}
break;
}
}
}
/*
* Decide what functions we need to run after run_actions()
* @param: none
*/
public function page_footer()
{
global $template, $user;
if(!empty($this->error))
{
$this->return_ary['ERROR_ACTION'] = 'return';
foreach($this->error as $cur_error)
{
if($cur_error['action'] == 'cancel')
{
$this->load_tpl = false; // make sure we don't load any template
$this->return_ary['ERROR_ACTION'] = 'cancel';
}
// replace lang vars if possible
$this->return_ary['ERROR'][] = (isset($user->lang[$cur_error['error']])) ? $user->lang[$cur_error['error']] : $cur_error['error'];
}
$this->return_ary['ERROR_COUNT'] = sizeof($this->return_ary['ERROR']);
}
if($this->load_tpl)
{
$template->set_filenames(array(
'body' => $this->tpl_file)
);
page_footer();
}
elseif(isset($this->return_ary))
{
echo json_encode($this->return_ary);
}
}
/*
* include a file if its functions or class does not exist yet
* always use this function for including files
*
* @param <string> $file The path to the file that needs to be included (relative to the phpbb root path & just the filename, i.e. 'index' for index.php)
* @param <string> $check The function or class that shouldn't exist if the file hasn't been included yet
* @param <bool> $class Set to true if you would like to check for a class and false if you would like to check for a function
*/
private function include_file($file, $check, $class = false)
{
global $phpbb_root_path, $phpEx;
if($class)
{
if(!class_exists($check))
{
include($phpbb_root_path . $file . '.' . $phpEx);
}
}
else
{
if(!function_exists($check))
{
include($phpbb_root_path . $file . '.' . $phpEx);
}
}
}
/*
* Add variables or arrays to the JSON return array
*
* @param: <array> $return_ary The array of variables -- the array needs to be structured like: array('varname' => 'value')
* @param: <bool> $force Set to true if you want to overwrite already existing values
*/
private function add_return($return_ary, $force = false)
{
foreach($return_ary as $key => $value)
{
if(!isset($this->return_ary[$key]) || $force)
{
$this->return_ary[$key] = $value;
}
}
}
/*
* Quickedit posts
* @param none
*/
private function quickedit()
{
global $db, $config, $auth, $template, $user;
// the first post is 1, so any post_id below 1 isn't possible
if($this->post_id < 1)
{
$this->error[] = array('error' => $user->lang['NO_MODE'], 'action' => 'cancel');
$mode = '';
//$this->tpl_load = false; // page_footer already does this
}
else
{
$qe_mode = request_var('qe_mode', '');
}
switch($qe_mode)
{
case 'init':
$sql = 'SELECT p.*, f.*, t.*
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f
WHERE p.post_id = ' . (int) $this->post_id . ' AND p.topic_id = t.topic_id';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Give a valid forum_id for image, smilies, etc. status
if(!isset($row['forum_id']) || $row['forum_id'] <= 0)
{
$forum_id = $this->forum_id;
}
else
{
$forum_id = $row['forum_id'];
}
// HTML, BBCode, Smilies, Images and Flash status
$bbcode_status = ($config['allow_bbcode'] && ($auth->acl_get('f_bbcode', $forum_id))) ? true : false;
$smilies_status = ($bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id)) ? true : false;
$img_status = ($bbcode_status && $auth->acl_get('f_img', $forum_id)) ? true : false;
$url_status = ($config['allow_post_links']) ? true : false;
$flash_status = ($bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash']) ? true : false;
$quote_status = ($auth->acl_get('f_reply', $forum_id)) ? true : false;
// check if the user is registered and if he is able to edit posts
if (!$user->data['is_registered'] && !$auth->acl_gets('f_edit', 'm_edit', $forum_id))
{
$this->error[] = array('error' => $user->lang['USER_CANNOT_EDIT'], 'action' => 'cancel');
}
if ($row['forum_status'] === ITEM_LOCKED)
{
// forum locked
$this->error[] = array('error' => $user->lang['FORUM_LOCKED'], 'action' => 'cancel');
}
elseif ((isset($row['topic_status']) && $row['topic_status'] === ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id))
{
// topic locked
$this->error[] = array('error' => $user->lang['TOPIC_LOCKED'], 'action' => 'cancel');
}
// check if the user is allowed to edit the selected post
if (!$auth->acl_get('m_edit', $forum_id))
{
if ($user->data['user_id'] != $row['poster_id'])
{
// user is not allowed to edit this post
$this->error[] = array('error' => $user->lang['USER_CANNOT_EDIT'], 'action' => 'cancel');
}
if (($row['post_time'] < time() - ($config['edit_time'] * 60)) && $config['edit_time'] > 0)
{
// user can no longer edit the post (exceeded edit time)
$this->error[] = array('error' => $user->lang['CANNOT_EDIT_TIME'], 'action' => 'cancel');
}
if ($row['post_edit_locked'])
{
// post has been locked in order to prevent editing
$this->error[] = array('error' => $user->lang['CANNOT_EDIT_POST_LOCKED'], 'action' => 'cancel');
}
}
// now normalize the post text
$text = utf8_normalize_nfc($row['post_text']);
$text = generate_text_for_edit($text, $row['bbcode_uid'], '');
// generate hidden fields for form
global $phpbb_root_path, $phpEx;
// this is just for the attachment_data
$message_parser = new parse_message();
$message_parser->message = $text['text'];
// Always check if the submitted attachment data is valid and belongs to the user.
// Further down (especially in submit_post()) we do not check this again.
$message_parser->get_submitted_attachment_data($row['poster_id']);
if ($row['post_attachment'])
{
// Do not change to SELECT *
$sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
FROM ' . ATTACHMENTS_TABLE . '
WHERE post_msg_id = ' . (int) $this->post_id . '
AND in_message = 0
AND is_orphan = 0
ORDER BY filetime DESC';
$result = $db->sql_query($sql);
$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
$db->sql_freeresult($result);
}
$s_hidden_fields = '<input type="hidden" name="lastclick" value="' . time() . '" />';
$s_hidden_fields .= build_hidden_fields(array(
'edit_post_message_checksum' => $row['post_checksum'],
'edit_post_subject_checksum' => (isset($post_data['post_subject'])) ? md5($row['post_subject']) : '',
'message' => $text['text'],
'full_editor' => true,
'subject' => $row['post_subject'],
'attachment_data' => $message_parser->attachment_data,
));
$template->assign_vars(array(
'U_ADVANCED_EDIT' => append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=edit&amp;f=' . $forum_id . "&amp;t={$row['topic_id']}&amp;p={$row['post_id']}"),
'S_HIDDEN_FIELDS' => $s_hidden_fields,
));
// Build custom bbcodes array
display_custom_bbcodes();
// Assign important template vars
$template->assign_vars(array(
'POST_TEXT' => (!empty($this->error)) ? '' : $text['text'], // Don't show the text if there was a permission error
'S_LINKS_ALLOWED' => $url_status,
'S_BBCODE_IMG' => $img_status,
'S_BBCODE_FLASH' => $flash_status,
'S_BBCODE_QUOTE' => $quote_status,
'S_BBCODE_ALLOWED' => $bbcode_status,
'MAX_FONT_SIZE' => (int) $config['max_post_font_size'],
));
$this->load_tpl = false;
$template->set_filenames(array(
'body' =>'jquery_base/quickedit.html')
);
// get parsed template
$tpl_content = $template->assign_display('body');
$this->add_return(array(
'TPL_BODY' => $tpl_content,
));
break;
case 'submit':
/*
* only include functions_posting if we actually need it
* make sure we don't include it if it already has been included by some other MOD
*/
$this->include_file('includes/functions_posting', 'submit_post');
$sql = 'SELECT p.*, f.*, t.*, u.*, p.icon_id AS post_icon_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . ' u
WHERE p.post_id = ' . (int) $this->post_id . '
AND p.topic_id = t.topic_id
AND p.poster_id = u.user_id';
$result = $db->sql_query($sql);
$post_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// Give a valid forum_id for image, smilies, etc. status
if(!isset($post_data['forum_id']) || $post_data['forum_id'] <= 0)
{
$post_data['forum_id'] = $this->forum_id;
}
// HTML, BBCode, Smilies, Images and Flash status
$bbcode_status = ($config['allow_bbcode'] && ($auth->acl_get('f_bbcode', $post_data['forum_id']) || $post_data['forum_id'] == 0) && $post_data['enable_bbcode']) ? true : false;
$smilies_status = ($bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $post_data['forum_id']) && $post_data['enable_smilies']) ? true : false;
$img_status = ($bbcode_status && $auth->acl_get('f_img', $post_data['forum_id'])) ? true : false;
$url_status = ($config['allow_post_links'] && $post_data['enable_magic_url']) ? true : false;
$flash_status = ($bbcode_status && $auth->acl_get('f_flash', $post_data['forum_id']) && $config['allow_post_flash']) ? true : false;
$quote_status = ($auth->acl_get('f_reply', $post_data['forum_id'])) ? true : false;
// check if the user is registered and if he is able to edit posts
if (!$user->data['is_registered'] && !$auth->acl_gets('f_edit', 'm_edit', $post_data['forum_id']))
{
$this->error[] = array('error' => $user->lang['USER_CANNOT_EDIT'], 'action' => 'cancel');
}
if ($post_data['forum_status'] === ITEM_LOCKED)
{
// forum locked
$this->error[] = array('error' => $user->lang['FORUM_LOCKED'], 'action' => 'cancel');
}
elseif ((isset($post_data['topic_status']) && $post_data['topic_status'] === ITEM_LOCKED) && !$auth->acl_get('m_edit', $post_data['forum_id']))
{
// topic locked
$this->error[] = array('error' => $user->lang['TOPIC_LOCKED'], 'action' => 'cancel');
}
// check if the user is allowed to edit the selected post
if (!$auth->acl_get('m_edit', $post_data['forum_id']))
{
if ($user->data['user_id'] != $post_data['poster_id'])
{
// user is not allowed to edit this post
$this->error[] = array('error' => $user->lang['USER_CANNOT_EDIT'], 'action' => 'cancel');
}
if (($post_data['post_time'] < time() - ($config['edit_time'] * 60)) && $config['edit_time'] > 0)
{
// user can no longer edit the post (exceeded edit time)
$this->error[] = array('error' => $user->lang['CANNOT_EDIT_TIME'], 'action' => 'cancel');
}
if ($post_data['post_edit_locked'])
{
// post has been locked in order to prevent editing
$this->error[] = array('error' => $user->lang['CANNOT_EDIT_POST_LOCKED'], 'action' => 'cancel');
}
}
// Add moderator edit to the moderator log
if (($user->data['user_id'] != $post_data['poster_id']) && ($auth->acl_get('m_edit', $post_data['forum_id'])))
{
add_log('mod', $post_data['forum_id'], $post_data['topic_id'], 'LOG_POST_EDITED', $post_data['topic_title'], (!empty($post_data['username'])) ? $post_data['username'] : $user->lang['GUEST']);
}
$post_text = utf8_normalize_nfc(request_var('contents', '', true));
$uid = $bitfield = '';
// start parsing the text for the database
$message_parser = new parse_message();
$message_parser->message = $post_text;
// Always check if the submitted attachment data is valid and belongs to the user.
// Further down (especially in submit_post()) we do not check this again.
$message_parser->get_submitted_attachment_data($post_data['poster_id']);
if ($post_data['post_attachment'])
{
// Do not change to SELECT *
$sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
FROM ' . ATTACHMENTS_TABLE . '
WHERE post_msg_id = ' . (int) $this->post_id . '
AND in_message = 0
AND is_orphan = 0
ORDER BY filetime DESC';
$result = $db->sql_query($sql);
$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
$db->sql_freeresult($result);
}
if(isset($post_data['bbcode_uid']) && $post_data['bbcode_uid'] > 0)
{
$message_parser->bbcode_uid = $post_data['bbcode_uid'];
}
// this will tell us if there are any errors with the post
$message_parser->parse($bbcode_status, ($url_status) ? $post_data['enable_magic_url'] : false, $smilies_status, $img_status, $flash_status, $quote_status, $config['allow_post_links'], true);
// insert info into the sql_ary
$uid = $message_parser->bbcode_uid;
$bitfield = $message_parser->bbcode_bitfield;
//now check if we need to set the edit time and edit count
if (!$auth->acl_get('m_edit', $post_data['forum_id']))
{
$edit_time = time();
$edit_count = $post_data['post_edit_count'] + 1;
$edit_user = $user->data['user_id'];
}
elseif ($auth->acl_get('m_edit', $post_data['forum_id']) && $post_data['post_edit_reason'] && $post_data['post_edit_user'] == $user->data['user_id'])
{
$edit_time = time();
$edit_count = $post_data['post_edit_count'] + 1;
$edit_user = $user->data['user_id'];
}
else
{
$edit_time = (isset($post_data['post_edit_time'])) ? $post_data['post_edit_time'] : 0;
$edit_user = (isset($post_data['post_edit_user'])) ? $post_data['post_edit_user'] : 0;
$edit_count = (isset($post_data['post_edit_count'])) ? $post_data['post_edit_count'] : 0;
}
// Create the data array for submit_post
$data = array(
// General Posting Settings
'forum_id' => $post_data['forum_id'],
'topic_id' => $post_data['topic_id'],
'icon_id' => $post_data['post_icon_id'],
'post_id' => $post_data['post_id'],
'poster_id' => $post_data['poster_id'],
'topic_replies' => $post_data['topic_replies'],
'topic_replies_real' => $post_data['topic_replies_real'],
'topic_first_post_id' => $post_data['topic_first_post_id'],
'topic_last_post_id' => $post_data['topic_last_post_id'],
'post_edit_user' => $edit_user,
'forum_parents' => $post_data['forum_parents'],
'forum_name' => $post_data['forum_name'],
'topic_poster' => $post_data['topic_poster'],
// Defining Post Options
'enable_bbcode' => $post_data['enable_bbcode'],
'enable_smilies' => $post_data['enable_smilies'],
'enable_urls' => $post_data['enable_magic_url'],
'enable_sig' => $post_data['enable_sig'],
'topic_attachment' => (isset($post_data['topic_attachment'])) ? (int) $post_data['topic_attachment'] : 0,
'poster_ip' => (isset($post_data['poster_ip'])) ? $post_data['poster_ip'] : $user->ip,
'attachment_data' => $message_parser->attachment_data,
'filename_data' => $message_parser->filename_data,
// Message Body
'message' => $message_parser->message,
'message_md5' => md5($message_parser->message),
// Values from generate_text_for_storage()
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
// Other Options
'post_edit_locked' => $post_data['post_edit_locked'],
'post_edit_reason' => ($post_data['post_edit_reason']) ? $post_data['post_edit_reason'] : '',
'topic_title' => $post_data['topic_title'],
'topic_time_limit' => ($post_data['topic_time_limit']) ? $post_data['topic_time_limit'] : 0,
// Email Notification Settings
'notify_set' => false,
'notify' => false,
'post_time' => 0,
'forum_name' => $post_data['forum_name'],
// Indexing
'enable_indexing' => true,
// 3.0.6
'force_approved_state' => true, // post has already been approved
);
$poll = array(
'poll_title' => $post_data['poll_title'],
'poll_length' => $post_data['poll_length'],
'poll_start' => $post_data['poll_start'],
'poll_max_options' => $post_data['poll_max_options'],
'poll_vote_change' => $post_data['poll_vote_change'],
);
// Get Poll Data
if ($poll['poll_start'])
{
$sql = 'SELECT poll_option_text
FROM ' . POLL_OPTIONS_TABLE . "
WHERE topic_id = {$data['topic_id']}
ORDER BY poll_option_id";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$poll['poll_options'][] = trim($row['poll_option_text']);
}
$db->sql_freeresult($result);
}
// Always check if the submitted attachment data is valid and belongs to the user.
// Further down (especially in submit_post()) we do not check this again.
$message_parser->get_submitted_attachment_data($post_data['poster_id']);
if ($post_data['post_attachment'])
{
// Do not change to SELECT *
$sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
FROM ' . ATTACHMENTS_TABLE . '
WHERE post_msg_id = ' . (int) $this->post_id . '
AND in_message = 0
AND is_orphan = 0
ORDER BY filetime DESC';
$result = $db->sql_query($sql);
$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
$db->sql_freeresult($result);
}
foreach($message_parser->warn_msg as $cur_error)
{
$this->error[] = array('error' => $cur_error, 'action' => 'return'); // by default we have a return error
}
// Don't execute all that if we already have errors
if(!sizeof($this->error))
{
/**
* Start parsing the message for displaying the post
* we only do this if there is no error or else we might just do useless database queries
* Pull attachment data
* @copyright (c) 2005 phpBB Group
*/
if ($post_data['post_attachment'] && $config['allow_attachments'])
{
$attach_list[] = (int) $post_data['post_id'];
}
else
{
$attach_list = array();
}
if (sizeof($attach_list))
{
if ($auth->acl_get('u_download') && (empty($post_data['forum_id']) || $auth->acl_get('f_download', $post_data['forum_id'])))
{
$sql = 'SELECT *
FROM ' . ATTACHMENTS_TABLE . '
WHERE ' . $db->sql_in_set('post_msg_id', $attach_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);
// No attachments exist, but post table thinks they do so go ahead and reset post_attach flags
if (!sizeof($attachments))
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_attachment = 0
WHERE ' . $db->sql_in_set('post_id', $attach_list);
$db->sql_query($sql);
}
}
}
// Add up the flag options...
$bbcode_options = (($post_data['enable_bbcode']) ? OPTION_FLAG_BBCODE : 0) + (($post_data['enable_smilies']) ? OPTION_FLAG_SMILIES : 0) + (($post_data['enable_magic_url']) ? OPTION_FLAG_LINKS : 0);
// Parse the post
$text = generate_text_for_display($data['message'], $data['bbcode_uid'], $data['bbcode_bitfield'], $bbcode_options);
// Parse attachments
if (!empty($attachments[$post_data['post_id']]))
{
parse_attachments($post_data['forum_id'], $text, $attachments[$post_data['post_id']], $update_count);
}
if (!$auth->acl_get('m_edit', $post_data['forum_id']))
{
$user->add_lang('viewtopic');
$display_username = get_username_string('full', $post_data['poster_id'], $post_data['username'], $post_data['user_colour'], $post_data['post_username']);
$l_edit_time_total = ($post_data['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
$l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time'], false, true), $edit_count);
if($post_data['post_edit_reason'])
{
$l_edited_by .= '<br /><strong>' . $user->lang['REASON'] . ':</strong> <em>' . $post_data['post_edit_reason'] . '</em>';
}
}
elseif ($auth->acl_get('m_edit', $post_data['forum_id']) && $post_data['post_edit_reason'] && $post_data['post_edit_user'] == $user->data['user_id'])
{
$user->add_lang('viewtopic');
$display_username = get_username_string('full', $user->data['user_id'], $user->data['username'], $user->data['user_colour'], $user->data['username']);
$l_edit_time_total = ($post_data['post_edit_count'] == 1) ? $user->lang['EDITED_TIME_TOTAL'] : $user->lang['EDITED_TIMES_TOTAL'];
$l_edited_by = sprintf($l_edit_time_total, $display_username, $user->format_date($post_data['post_edit_time'], false, true), $edit_count);
if($post_data['post_edit_reason'])
{
$l_edited_by .= '<br /><strong>' . $user->lang['REASON'] . ':</strong> <em>' . $post_data['post_edit_reason'] . '</em>';
}
}
else
{
$l_edited_by = '0';
}
$this->add_return(array(
'EDITED_BY' => $l_edited_by,
'TEXT' => $text,
));
$this->load_tpl = false;
$this->add_return(array(
'SUCCESS_MESSAGE' => $user->lang['PJB_QUICKEDIT_SUCCESS_MSG'],
'SUCCESS_TITLE' => $user->lang['PJB_QUICKEDIT_SUCCESS'],
));
/*
* Don't run submit_post before we checked for errors
* $mode is always edit as we just edit a post with this MOD
* $username is set to $user->data['username'] as we don't need the clean username for the logs
*/
submit_post('edit', $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data);
}
else
{
$this->load_tpl = false;
}
break;
default:
}
}
}
<div id="pjB-qe-form">
<form id="pjB-adv-form" action="{U_ADVANCED_EDIT}" method="post">
<!-- IF S_BBCODE_ALLOWED -->
<div id="quickedit-buttons" style="font-family:Verdana,Helvetica,Arial,sans-serif;">
<input type="button" value=" B " id="bbcode0" class="button2" style="width: 30px; font-size:0.9em; font-weight:bold;" title="{L_BBCODE_B_HELP}" />
<input type="button" value=" i " id="bbcode2" class="button2" style="width: 30px; font-size:0.9em; font-style: italic;" title="{L_BBCODE_I_HELP}" />
<input type="button" value=" u " id="bbcode4" class="button2" style="width: 30px; font-size:0.9em; text-decoration: underline;" title="{L_BBCODE_U_HELP}" />
<!-- IF S_BBCODE_QUOTE -->
<input type="button" value="Quote" id="bbcode6" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_Q_HELP}" />
<!-- ENDIF -->
<input type="button" value="Code" id="bbcode8" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_C_HELP}" />
<input type="button" value="List" id="bbcode10" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_L_HELP}" />
<input type="button" value="List=" id="bbcode12" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_O_HELP}" />
<input type="button" value="[*]" id="bbcode-1" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_LISTITEM_HELP}" />
<!-- IF S_BBCODE_IMG -->
<input type="button" value="Img" id="bbcode14" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_P_HELP}" />
<!-- ENDIF -->
<!-- IF S_LINKS_ALLOWED -->
<input type="button" value="URL" id="bbcode16" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_W_HELP}" />
<!-- ENDIF -->
<!-- IF S_BBCODE_FLASH -->
<input type="button" value="Flash" id="bbcode18" class="button2" style="width: 30px; font-size:0.9em;" title="{L_BBCODE_D_HELP}" />
<!-- ENDIF -->
<select id="addbbcode202" name="addbbcode202" title="{L_BBCODE_F_HELP}">
<option value="50">{L_FONT_TINY}</option>
<option value="85">{L_FONT_SMALL}</option>
<option value="100" selected="selected">{L_FONT_NORMAL}</option>
<!-- IF not MAX_FONT_SIZE or MAX_FONT_SIZE >= 150 -->
<option value="150">{L_FONT_LARGE}</option>
<!-- IF not MAX_FONT_SIZE or MAX_FONT_SIZE >= 200 -->
<option value="200">{L_FONT_HUGE}</option>
<!-- ENDIF -->
<!-- ENDIF -->
</select>
<!-- BEGIN custom_tags -->
<input type="button" class="button2" value="{custom_tags.BBCODE_TAG}" id="bbcode{custom_tags.BBCODE_ID}" title="{custom_tags.BBCODE_HELPLINE}" style="width: 30px; font-size:0.9em;" />
<!-- END custom_tags -->
</div>
<!-- ENDIF -->
<div id="jqe-message-box">
<textarea name="message" id="jqe-message" class="inputbox" rows="15" cols="76" onselect="qe_storeCaret(this);" onclick="qe_storeCaret(this);" onkeyup="qe_storeCaret(this);" onfocus="qe_initInsertions();" >{POST_TEXT}</textarea><br />
<br />
</div>
<fieldset id="jqe-adv-fieldset">
{S_HIDDEN_FIELDS}
<input class="button1" type="button" id="submit_jqe" value="{L_SUBMIT}" style="font-size: 0.9em;" />
<input class="button2" type="button" id="cancel_jqe" value="{L_CANCEL}" style="font-size: 0.9em;" />
<input class="button2" type="submit" id="adv_jqe" value="{L_ADVANCED_EDIT}" style="font-size: 0.9em;" />
{S_FORM_TOKEN}
</fieldset>
</form>
<script type="text/javascript">
// <![CDATA[
/*
* This is needed in order to have a correct listing of the custom bbcodes
*/
bbcode = new Array();
qe_bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[quote]','[/quote]','[code]','[/code]','[list]','[/list]','[list=]','[/list]','[img]','[/img]','[url]','[/url]','[flash=]', '[/flash]','[size=]','[/size]'<!-- BEGIN custom_tags -->, {custom_tags.BBCODE_NAME}<!-- END custom_tags -->);
// ]]>
</script>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment