Example #1
0
<?php

//Update dislike post button
require_once '../includes/functions.inc.php';
require_once '../includes/admin.inc.php';
if (isset($_POST['pid']) && isset($_SESSION['uid'])) {
    $pid = $_POST['pid'];
    $uid = $_SESSION['uid'];
    $post_vote = post_vote_load($pid, $uid);
    print '<script type="text/javascript">
			$("#post_dislike_pid_' . $pid . '").html("' . count_post_dislikes($pid) . ' Dislike' . (count_post_dislikes($pid) == 0 || count_post_dislikes($pid) == 1 ? '' : 's') . '").' . ($post_vote['PostVote_Dislike'] == 0 ? 'remove' : 'add') . 'Class("clicked");
			</script>';
}
Example #2
0
function view_post($pid, $uid, $button = 0)
{
    //Return post from post ID
    $output = '';
    $post = post_load($pid);
    $user = user_load($post['User_ID']);
    $course = course_load($post['Course_ID']);
    $cid = $post['Course_ID'];
    $role = role_load($user['Role_ID']);
    $post_vote = post_vote_load($pid, $_SESSION['uid']);
    $post_follow = post_follow_load($pid, $_SESSION['uid']);
    $post_rate = post_rate_load($pid, $_SESSION['uid']);
    $post = post_load($pid);
    $title = $post['Post_Title'];
    $email = $user['User_Mail'];
    $size = 40;
    $default = DEFAULT_AVATAR;
    $grav_url = "http://0.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?d=" . $default . "&s=" . $size;
    $output .= '<div class="post ' . ($i == 0 ? 'first' : '') . '">';
    $output .= '<a class="author" href="' . (isset($post['Post_Hide_Name']) && $post['Post_Hide_Name'] == 1 || !user_existed($post['User_ID']) ? '#' : '?p=user/' . $user['User_Username']) . '"><img src="' . (isset($post['Post_Hide_Name']) && $post['Post_Hide_Name'] == 1 || !user_existed($post['User_ID']) ? $default : $grav_url) . '" width="40px"/></a>';
    $output .= '<div class="post_right_detail">';
    $output .= '<span class="author_name' . ($user['Role_ID'] == 3 ? ' lecturer' : '') . '">' . (isset($post['Post_Hide_Name']) && $post['Post_Hide_Name'] == 1 || !user_existed($post['User_ID']) ? '' : '<a href="?p=user/' . $user['User_Username'] . '">') . (isset($post['Post_Hide_Name']) && $post['Post_Hide_Name'] == 1 || !user_existed($post['User_ID']) ? 'Anonymous' : (isset($user['User_Fullname']) ? $user['User_Fullname'] : $user['User_Username'])) . (isset($post['Post_Hide_Name']) && $post['Post_Hide_Name'] == 1 || !user_existed($post['User_ID']) ? '' : '</a>') . '</span><br/>';
    $output .= '<a class="post_title" href="?p=question/' . $post['Post_URL'] . '">' . $post['Post_Title'] . '</a><br/>';
    $output .= '<a class="course_code" href="?p=course/' . $course['Course_Code'] . '">' . $course['Course_Code'] . '</a><a href="?p=course/' . $course['Course_Code'] . '/week/' . $post['Post_Week'] . '"><span class="course_name">.' . $course['Course_Name'] . '</span> > <span class="post_week">Week ' . $post['Post_Week'] . '</span></a><br/>';
    $output .= '<span class="post_content">' . $post['Post_Question'] . '</span><br/>';
    $output .= $post['Post_Answer'] != '' ? '<div class="post_answer"><div class="post_answer_label">Answer:</div><div class="post_answer_content">' . $post['Post_Answer'] . '</div></div>' : '';
    $output .= $uid != 0 && $post_rate['User_ID'] != $uid && $_SESSION['rid'] != 1 ? star_rating($pid) : '<div title="Your rating" id="post_rate_pid_' . $pid . '" class="rate_widget">' . star_rating_update($pid) . '</div><div title="Average rating: ' . average_post_rates_with_decimal($pid, 1) . '" id="average_post_rate_pid_' . $pid . '" class="average_rate">' . star_rating_average($pid) . '</div>';
    $output .= $uid != 0 ? '<div style="display: none" id="save_post_rate_pid_' . $pid . '"></div>' : '';
    $output .= $uid != 0 ? '<a title="' . ($post_vote['PostVote_Like'] == 0 ? 'Like' : 'Unlike') . ' this post" class="button' . ($post_vote['PostVote_Like'] == 0 ? ' like' : ' like clicked') . (!course_belonged($cid, $_SESSION['uid']) && $cid != 0 && $_SESSION['rid'] != 1 ? ' not_belonged' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 1 ? ' is_admin' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 4 && $course['Course_For_Guest'] == 1 ? ' guest_mode' : '') . '" id="post_like_pid_' . $pid . '">' . count_post_likes($pid) . ' Like' . (count_post_likes($pid) == 0 || count_post_likes($pid) == 1 ? '' : 's') . '</a>' : '<a title="Like this post" class="button like disabled" id="post_like_pid_' . $pid . '">' . count_post_likes($pid) . ' Like' . (count_post_likes($pid) == 0 || count_post_likes($pid) == 1 ? '' : 's') . '</a>';
    $output .= $uid != 0 ? '<div style="display: none" id="save_post_like_pid_' . $pid . '"></div>' : '';
    $output .= $uid != 0 ? '<a title="' . ($post_vote['PostVote_Dislike'] == 0 ? 'Dislike' : 'Undislike') . ' this post" class="button' . ($post_vote['PostVote_Dislike'] == 0 ? ' dislike' : ' dislike clicked') . (!course_belonged($cid, $_SESSION['uid']) && $cid != 0 && $_SESSION['rid'] != 1 ? ' not_belonged' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 1 ? ' is_admin' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 4 && $course['Course_For_Guest'] == 1 ? ' guest_mode' : '') . '" id="post_dislike_pid_' . $pid . '">' . count_post_dislikes($pid) . ' Dislike' . (count_post_dislikes($pid) == 0 || count_post_dislikes($pid) == 1 ? '' : 's') . '</a>' : '<a title="Dislike this post" class="button dislike disabled" id="post_dislike_pid_' . $pid . '">' . count_post_dislikes($pid) . ' Dislike' . (count_post_dislikes($pid) == 0 || count_post_dislikes($pid) == 1 ? '' : 's') . '</a>';
    $output .= $uid != 0 ? '<div style="display: none" id="save_post_dislike_pid_' . $pid . '"></div>' : '';
    $output .= $uid != 0 ? '<a title="' . ($post_follow['User_ID'] != $uid ? 'Follow' : 'Unfollow') . ' this post" class="button' . ($post_follow['User_ID'] != $uid ? ' follow' : ' follow clicked') . (!course_belonged($cid, $_SESSION['uid']) && $cid != 0 && $_SESSION['rid'] != 1 ? ' not_belonged' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 1 ? ' is_admin' : '') . (isset($_SESSION['rid']) && $_SESSION['rid'] == 4 && $course['Course_For_Guest'] == 1 ? ' guest_mode' : '') . '" id="post_follow_pid_' . $pid . '">' . count_post_follows($pid) . ' Follow' . (count_post_follows($pid) == 0 || count_post_follows($pid) == 1 ? '' : 's') . '</a>' : '<a title="Follow this post" class="button follow disabled" id="post_follow_pid_' . $pid . '">' . count_post_follows($pid) . ' Follow' . (count_post_follows($pid) == 0 || count_post_follows($pid) == 1 ? '' : 's') . '</a>';
    $output .= '<div style="display: none" id="save_post_follow_pid_' . $pid . '"></div>';
    $output .= '<a id="comments_count_pid_' . $pid . '" title="Leave a comment" class="button comment_toggle' . ($uid == 0 ? ' not_loggedin' : '') . (count_comments($pid) == 0 ? ' no_comment' : '') . '">' . count_comments($pid) . ' Comment' . (count_comments($pid) == 0 || count_comments($pid) == 1 ? '' : 's') . '</a>';
    $output .= '<span class="post_time">' . ago($post['Post_Created']) . '</span>';
    $output .= $uid != 0 ? list_comments($pid) : list_comments_without_right($pid);
    $output .= $uid != 0 ? '<script>
				$("#post_like_pid_' . $pid . '").click(function(){
					postLike(' . $pid . ');
				});
				$("#post_dislike_pid_' . $pid . '").click(function(){
					postDislike(' . $pid . ');
				});
				$("#post_follow_pid_' . $pid . '").click(function(){
					postFollow(' . $pid . ');
				});
				</script>
				' : '';
    $output .= '<script>
				if ($("#comments_pid_' . $pid . '").css("display") == "none") {
					$("#comments_count_pid_' . $pid . '").removeClass("clicked");
				} else if ($("#comments_pid_' . $pid . '").css("display") == "block") {
					$("#comments_count_pid_' . $pid . '").addClass("clicked");
				}
				$("#comments_count_pid_' . $pid . '").click(function(){
					if ($(this).hasClass("not_loggedin") && $(this).hasClass("no_comment")) {
						openLogin();
					} else {
						toggle_comments(' . "'" . 'comments_pid_' . $pid . "'" . ',this);
					}
					if ($("#comments_pid_' . $pid . '").css("display") == "none") {
						$("#comments_count_pid_' . $pid . '").removeClass("clicked");
					} else if ($("#comments_pid_' . $pid . '").css("display") == "block") {
						$("#comments_count_pid_' . $pid . '").addClass("clicked");
					}
				});
				</script>';
    $output .= '</div></div>';
    $output .= $button == 1 && isset($_SESSION['rid']) && course_belonged($cid, $_SESSION['uid']) && ($uid == $post['User_ID'] || $_SESSION['rid'] != 2) ? '<form style="width: 25px;float: left;" method="POST" action="?p=post/edit"><input type="hidden" name="pid" value="' . $post['Post_ID'] . '" /><input type="hidden" name="old_cid" value="' . $post['Course_ID'] . '" /><input type="hidden" name="old_week" value="' . $post['Post_Week'] . '" /><input type="hidden" name="old_title" value="' . $post['Post_Title'] . '" /><input type="hidden" name="old_url" value="' . $post['Post_URL'] . '" /><input type="hidden" name="old_body" value="' . str_replace('"', "'", $post['Post_Question']) . '" /><input name="post_edit" type="submit" value="Edit"/></form><form method="POST" action="?p=post/delete"><input type="hidden" name="pid" value="' . $post['Post_ID'] . '" /><input title="Delete" name="post_delete" type="submit" value="Delete"/></form>' : '';
    return $output;
}