Skip to content

Instantly share code, notes, and snippets.

@markbratanov
Created December 16, 2015 04:41
Show Gist options
  • Save markbratanov/e62617b040d7674bb5e0 to your computer and use it in GitHub Desktop.
Save markbratanov/e62617b040d7674bb5e0 to your computer and use it in GitHub Desktop.
Two important clocks of code to create new messages and polls.
// Sources/Post.php@1828
// This bit creates a new poll in the database
if (isset($_REQUEST['poll']))
{
// Create the poll.
$smcFunc['db_insert']('',
'{db_prefix}polls',
array(
'question' => 'string-255', 'hide_results' => 'int', 'max_votes' => 'int', 'expire_time' => 'int', 'id_member' => 'int',
'poster_name' => 'string-255', 'change_vote' => 'int', 'guest_vote' => 'int'
),
array(
$_POST['question'], $_POST['poll_hide'], $_POST['poll_max_votes'], (empty($_POST['poll_expire']) ? 0 : time() + $_POST['poll_expire'] * 3600 * 24), $user_info['id'],
$_POST['guestname'], $_POST['poll_change_vote'], $_POST['poll_guest_vote'],
),
array('id_poll')
);
$id_poll = $smcFunc['db_insert_id']('{db_prefix}polls', 'id_poll');
// Create each answer choice.
$i = 0;
$pollOptions = array();
foreach ($_POST['options'] as $option)
{
$pollOptions[] = array($id_poll, $i, $option);
$i++;
}
$smcFunc['db_insert']('insert',
'{db_prefix}poll_choices',
array('id_poll' => 'int', 'id_choice' => 'int', 'label' => 'string-255'),
$pollOptions,
array('id_poll', 'id_choice')
);
}
// Sources/Subs-Post.php@1804
// This creates a new post. It uses their special format $smcFunc['db_insert'](...)
// Insert the post.
$smcFunc['db_insert']('',
'{db_prefix}messages',
array(
'id_board' => 'int', 'id_topic' => 'int', 'id_member' => 'int', 'subject' => 'string-255', 'body' => (!empty($modSettings['max_messageLength']) && $modSettings['max_messageLength'] > 65534 ? 'string-' . $modSettings['max_messageLength'] : 'string-65534'),
'poster_name' => 'string-255', 'poster_email' => 'string-255', 'poster_time' => 'int', 'poster_ip' => 'string-255',
'smileys_enabled' => 'int', 'modified_name' => 'string', 'icon' => 'string-16', 'approved' => 'int',
),
array(
$topicOptions['board'], $topicOptions['id'], $posterOptions['id'], $msgOptions['subject'], $msgOptions['body'],
$posterOptions['name'], $posterOptions['email'], time(), $posterOptions['ip'],
$msgOptions['smileys_enabled'] ? 1 : 0, '', $msgOptions['icon'], $msgOptions['approved'],
),
array('id_msg')
);
$msgOptions['id'] = $smcFunc['db_insert_id']('{db_prefix}messages', 'id_msg');
// Something went wrong creating the message...
if (empty($msgOptions['id']))
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment