Skip to content

Commit

Permalink
WIP #882 Add more hooks v2
Browse files Browse the repository at this point in the history
xmlhttp.php
  • Loading branch information
Omar Gonzalez committed Jul 18, 2014
1 parent 4a3bb6d commit 93e678a
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions xmlhttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
"limit" => $limit
);

$plugins->run_hooks("xmlhttp_get_users_start");

$query = $db->simple_select("users", "uid, username", "username LIKE '".$db->escape_string_like($mybb->input['query'])."%'", $query_options);
if($limit == 1)
{
Expand All @@ -173,6 +175,8 @@
}
}

$plugins->run_hooks("xmlhttp_get_users_end");

echo json_encode($data);
exit;
}
Expand Down Expand Up @@ -204,7 +208,6 @@
xmlhttp_error($lang->thread_doesnt_exist);
}
}

// We're editing a thread subject.
else if($mybb->get_input('tid', 1))
{
Expand All @@ -227,6 +230,7 @@
{
exit;
}

// Fetch the specific forum this thread/post is in.
$forum = get_forum($thread['fid']);

Expand All @@ -239,6 +243,8 @@
// Fetch forum permissions.
$forumpermissions = forum_permissions($forum['fid']);

$plugins->run_hooks("xmlhttp_edit_subject_start");

// If this user is not a moderator with "caneditposts" permissions.
if(!is_moderator($forum['fid'], "caneditposts"))
{
Expand Down Expand Up @@ -322,6 +328,8 @@
// Send our headers.
header("Content-type: application/json; charset={$charset}");

$plugins->run_hooks("xmlhttp_edit_subject_end");

$mybb->input['value'] = $parser->parse_badwords($mybb->get_input('value'));

// Spit the subject back to the browser.
Expand Down Expand Up @@ -357,6 +365,8 @@
// Fetch forum permissions.
$forumpermissions = forum_permissions($forum['fid']);

$plugins->run_hooks("xmlhttp_edit_post_start");

// If this user is not a moderator with "caneditposts" permissions.
if(!is_moderator($forum['fid'], "caneditposts"))
{
Expand Down Expand Up @@ -388,6 +398,9 @@
xmlhttp_error($lang->no_permission_edit_post);
}
}

$plugins->run_hooks("xmlhttp_edit_post_end");

if($mybb->get_input('do') == "get_post")
{
// Send our headers.
Expand Down Expand Up @@ -535,6 +548,8 @@
$editedmsg_response = str_replace(array("\r", "\n"), "", $editedmsg);
}

$plugins->run_hooks("xmlhttp_update_post");

echo json_encode(array("message" => $post['message']."\n", "editedmsg" => $editedmsg_response));
exit;
}
Expand All @@ -550,6 +565,8 @@
// Divide up the cookie using our delimeter
$multiquoted = explode("|", $mybb->cookies['multiquote']);

$plugins->run_hooks("xmlhttp_get_multiquoted_start");

// No values - exit
if(!is_array($multiquoted))
{
Expand Down Expand Up @@ -593,13 +610,15 @@

require_once MYBB_ROOT."inc/functions_posting.php";

$plugins->run_hooks("xmlhttp_get_multiquoted_intermediate");

// Query for any posts in the list which are not within the specified thread
$query = $db->query("
SELECT p.subject, p.message, p.pid, p.tid, p.username, p.dateline, t.fid, p.visible, u.username AS userusername
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
WHERE {$from_tid}p.pid IN ($quoted_posts) {$unviewable_forums}
WHERE {$from_tid}p.pid IN ({$quoted_posts}) {$unviewable_forums} {$inactiveforums}
ORDER BY p.dateline
");
while($quoted_post = $db->fetch_array($query))
Expand All @@ -618,6 +637,9 @@

// Send our headers.
header("Content-type: application/json; charset={$charset}");

$plugins->run_hooks("xmlhttp_get_multiquoted_end");

echo json_encode(array("message" => $message));
exit;
}
Expand All @@ -637,6 +659,9 @@
"imagestring" => $randomstr,
"dateline" => TIME_NOW
);

$plugins->run_hooks("xmlhttp_refresh_captcha");

$db->insert_query("captcha", $regimagearray);
header("Content-type: application/json; charset={$charset}");
echo json_encode(array("imagehash" => $imagehash));
Expand All @@ -654,6 +679,8 @@
}
$imagestring = $db->fetch_field($query, 'imagestring');

$plugins->run_hooks("xmlhttp_validate_captcha");

if(my_strtolower($imagestring) == my_strtolower($mybb->get_input('imagestring')))
{
//echo json_encode(array("success" => $lang->captcha_matches));
Expand All @@ -672,6 +699,9 @@
$password = str_replace(array(unichr(160), unichr(173), unichr(0xCA), dec_to_utf8(8238), dec_to_utf8(8237), dec_to_utf8(8203)), array(" ", "-", "", "", "", ""), $password);

header("Content-type: application/json; charset={$charset}");

$plugins->run_hooks("xmlhttp_complex_password");

if(!preg_match("/^.*(?=.{".$mybb->settings['minpasswordlength'].",})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password))
{
echo json_encode($lang->complex_password_fails);
Expand Down Expand Up @@ -727,6 +757,8 @@
// Check if the username is actually already in use
$user = get_user_by_username($username);

$plugins->run_hooks("xmlhttp_username_availability");

if($user['uid'])
{
$lang->username_taken = $lang->sprintf($lang->username_taken, htmlspecialchars_uni($username));
Expand Down Expand Up @@ -761,6 +793,8 @@
// Check if the username actually exists
$user = get_user_by_username($username);

$plugins->run_hooks("xmlhttp_username_exists");

if($user['uid'])
{
$lang->valid_username = $lang->sprintf($lang->valid_username, htmlspecialchars_uni($username));
Expand All @@ -785,6 +819,9 @@
"order_by" => "username",
"order_dir" => "asc"
);

$plugins->run_hooks("xmlhttp_get_buddyselect_start");

$timecut = TIME_NOW - $mybb->settings['wolcutoff'];
$query = $db->simple_select("users", "uid, username, usergroup, displaygroup, lastactive, lastvisit, invisible", "uid IN ({$mybb->user['buddylist']})", $query_options);
$online = array();
Expand All @@ -804,6 +841,9 @@
}
$online = implode("", $online);
$offline = implode("", $offline);

$plugins->run_hooks("xmlhttp_get_buddyselect_end");

eval("\$buddy_select = \"".$templates->get("xmlhttp_buddyselect")."\";");
echo $buddy_select;
}
Expand Down

0 comments on commit 93e678a

Please sign in to comment.