Example #1
0
 /**
  * inserts a new comment
  *
  * @param $data array
  *
  * @return int(id)|string(error)
  */
 public static function new_comment($data)
 {
     $database = new Database();
     $post = new Post();
     $PostID = $data['post_id'];
     $content = $data['content'];
     $token = $data['token'];
     if (empty(trim($content))) {
         die("Comment can't be empty");
     }
     $qna = new QNA();
     if (!is_object($qna->get_question($PostID)) && !is_array($post->get_post($PostID, true))) {
         die("Error! Post was not found.");
     }
     if (!Token::validateToken($token)) {
         die("Error! Please try again later");
     }
     unset($data['token']);
     $data['uid'] = USER_ID;
     $insert = $database->insert_data(TABLE_COMMENTS, $data);
     if ($insert === true && $database->error === false) {
         // success
         return (int) $database->lastId;
     } else {
         return array_shift($database->errors);
     }
 }
Example #2
0
 public static function postDate($id)
 {
     $QNA = new QNA();
     $type = Post::PorQ($id);
     if ($type == 'q' || $type == 'c') {
         $post = $QNA->get_question($id) ?: (object) Comment::getComment($id);
         $date = $post->created;
         $html = "<a href='" . self::pLink($id) . "' title='{$date} GMT" . Date('P') . "' class='datetime'>{$date}</a>";
     } elseif ($type == 'p') {
         $post = Post::get_post($id, true);
         $date = $post['date'];
         $html = "<a href='" . self::pLink($id) . "' title='{$date} GMT" . Date('P') . "' class='datetime'>{$date}</a>";
     } else {
         return false;
     }
     return $html;
 }
Example #3
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$sec = "questions";
$pageTitle = "Ask a new question";
include ROOT_PATH . 'inc/head.php';
if (!$session->is_logged_in()) {
    $session->message("You must log in to submit a new question.", "", "danger");
}
$QNA = new QNA();
$sections = $QNA->get_sections();
?>
<body>
	<div class="ui container section">

		<div class="ui raised very padded segment">
			<h3>Write a new story</h3>
				<form class="ui form create_q" action="" method="POST">
					<div class="field">
						<label>Title</label>
						<input type="text" name="title" placeholder="Title">

					</div>
					<div class="field">
						<label for="content">Content</label>
						<textarea name="content" rows="7"></textarea>
					</div>
					<div class="field">
						<label>Select section</label>
						<div class="ui selection dropdown" id="q_c_dropdown">
							<input type="hidden" name="section">
Example #4
0
					</div>
					<input type="hidden" name="post_id" value="<?php 
echo $id;
?>
" >
					<input type="hidden" name="comment_token" value="<?php 
echo Token::generateToken();
?>
" >
					<button name="comment" id="subcomment" style="display:none;" class="ui blue submit disabled icon button">Submit</button>
				</form>
				<br>
				<div id="comments">
					<?php 
foreach ($comments as $c) {
    $voted = QNA::has_voted($c->id, USER_ID);
    $votes = Comment::get_votes($c->id);
    $votes = $votes > 0 ? '+' . $votes : null;
    $self = $c->uid === USER_ID;
    if ($c->last_modified > $c->created) {
        $edited = "(edited <span id='editedDate' title=\"{$c->created}\">{$c->created}</span>)";
    } else {
        $edited = "";
    }
    $c->path = $c->path ?: DEF_PIC;
    ?>
					<div class="ui minimal comments">
						<div class="ui comment padded segment" id="<?php 
    echo $c->id;
    ?>
" comment-id="<?php 
Example #5
0
<div class="tab-questions">
<?php 
$QNA = new QNA();
$questions = $QNA->get_questions_by_user(USER_ID);
foreach ($questions as $q) {
    ?>
	<div class="item">
		<div class="ui grid">
			<div class="fourteen wide column">
				<a href='/questions/question.php?id=<?php 
    echo $q->id;
    ?>
'><h4><?php 
    echo $q->title;
    ?>
</h4></a>
				<div class="time" id="post-date"><?php 
    echo $q->created;
    ?>
</div>
			</div>
			<div class="two wide column">
			
				<?php 
    if ($q->status == "1") {
        ?>
						<p class="status" title="Public"><?php 
        echo $pub;
        ?>
</p>
					<?php 
Example #6
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$QNA = new QNA();
$sections = $QNA->get_sections();
$cp = isset($_GET['page']) ? $_GET['page'] : 1;
$rpp = 6;
$sec = isset($_GET['section']) ? $_GET['section'] : NULL;
foreach ($sections as $s) {
    switch ($s['acronym']) {
        case $sec:
            $sec_name = $s['title'];
            $QNA->section = $s['id'];
            $qs = $QNA->get_questions();
            $count = count($qs);
            $pag = new Pagination($count, $cp, $rpp);
            $offset = $pag->offset();
            $qs = $QNA->get_questions($rpp, $offset);
            break 2;
            // breaks out of the two casses (foreach and switch)
        // breaks out of the two casses (foreach and switch)
        default:
            $qs = $QNA->get_questions();
            $count = count($qs);
            $pag = new Pagination($count, $cp, $rpp);
            $offset = $pag->offset();
            $qs = $QNA->get_questions($rpp, $offset);
            $sec_name = 'All';
            break;
    }
}
Example #7
0
<div class="tab-questions">
<?php 
$QNA = new QNA();
$qs = $QNA->get_questions_by_user($UserID);
foreach ($qs as $q) {
    ?>
	<div class="item">
			<a href='/questions/question.php?id=<?php 
    echo $q->id;
    ?>
'><h4><?php 
    echo $q->title;
    ?>
</h4></a>
			<div class="time" id="post-date"><?php 
    echo $q->created;
    ?>
</div>
	</div><hr>
<?php 
}
?>
</div><br>

<script>
	$('.item').each(function(index, value) {
		$date = $(this).find('#post-date').text();
		$(this).find('#post-date').text(moment($date).fromNow());
	});
</script>
Example #8
0
" >
	<input type="hidden" name="feed_token" value="<?php 
    echo Token::generateToken();
    ?>
" >
	<button name="feed" class="ui blue submit icon button">Submit</button>
</form>
<br>
<div class="ui relaxed divided items" id="profile_feed_comments">
<?php 
}
if (empty($posts)) {
    echo "<p id='emptycmt'>There's nothing here!</p>";
} else {
    foreach ($posts as $post) {
        $votes_count = QNA::get_votes($post->id) ?: "0";
        $cCount = count($comments = Comment::get_comments($post->id));
        $post->img_path = $post->img_path ?: DEF_PIC;
        ?>

		<div class="item">
			<a href="/user/<?php 
        echo $post->uid;
        ?>
/" class="ui tiny image">
				<img src="<?php 
        echo $post->img_path;
        ?>
">
			</a>
			<div class="content">
Example #9
0
     $QNA = new QNA($PostID);
     // check if question exists
     $question = $QNA->get_question();
     if (!is_object($question)) {
         die(json_encode(['status' => false, 'err' => 'Question was not found.']));
     }
     $save = $QNA->save_post();
     if ($save === true) {
         die(json_encode(['status' => true]));
     } else {
         die(json_encode(['status' => false, 'err' => $save]));
     }
     break;
 case 'unsave':
     $PostID = sanitize_id($data['id']);
     $QNA = new QNA($PostID);
     // check if question exists
     $question = $QNA->get_question();
     if (!is_object($question)) {
         die(json_encode(['status' => false, 'err' => 'Question was not found.']));
     }
     $save = QNA::remove_saved($PostID);
     if ($save === true) {
         die(json_encode(['status' => true]));
     } else {
         die(json_encode(['status' => false, 'err' => $save]));
     }
     break;
 case 'post_delete':
     $PostID = sanitize_id($data['id']);
     $post = new Post();
Example #10
0
require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$sec = "questions";
$pageTitle = "Generate a new question";
if (!$session->is_logged_in()) {
    $session->message("You must log in to submit a new question.", "", "danger");
}
if (isset($_POST['submit'])) {
    $data = $_POST;
    $token = $data['token'];
    if (!Token::validateToken($token)) {
        die(json_encode(['status' => false, 'err' => 'Token is not valid']));
    }
    unset($data['token']);
    unset($data['submit']);
    $data['uid'] = USER_ID;
    $QNA = new QNA();
    $gen = $QNA->generate_question($data);
    Redirect::RedirectTo('/questions/question.php?id=' . $gen);
}
include ROOT_PATH . 'inc/head.php';
?>
<body>
	<div class="ui container section">
		<div class="ui raised very padded segment">
			<h2>Generate a story</h2>
			<p>Random title and content will be generated by using the <a href="http://loripsum.net">loripsum.net</a> api.<br>
      You can pass custom options for the content to be generated.</p><br>
				<form class="ui form create_q" method="POST">
          <div class="field">
            <label for="fruit">Number of Paragraph</label>
            <select name='num'>
Example #11
0
require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$pageTitle = "Admin Control Panel";
$session->adminLock();
if (isset($_POST['rp_rm']) && $_POST['rp_rm'] == 'true') {
    $id = $_POST['id'];
    Admin::removeReport($id);
    echo "1";
    exit;
}
$id = $_GET['id'];
$type = Post::PorQ($id);
if (!$type) {
    Redirect::redirectTo('404');
}
if ($type == 'q') {
    $QNA = new QNA();
    $post = $QNA->get_question($id);
    $reps = QNA::get_reports($id);
} else {
    $post = (object) Comment::getComment($id);
    $reps = Comment::get_reports($id);
}
$sec = "staff";
include ROOT_PATH . 'inc/head.php';
?>

<body>
	<div class="main" id="admincp">
		<div class="ui container section rep_mng">
			<?php 
if ($type == 'q') {
Example #12
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$pageTitle = "Admin Control Panel";
$session->adminLock();
$admin = new Admin();
$QNA = new QNA();
$total_reports = QNA::get_reports_count();
$users_count = count($admin->getAllUsers());
$qs_count = QNA::get_questions_count();
$qs = $QNA->get_questions(5, 0, true);
$users = $admin->getAllUsers(6, 0);
$sections = QNA::get_sections();
$admin = new Admin();
$count = count($admin->getTraffic());
$database = new Database();
$sec = "staff";
include ROOT_PATH . 'inc/head.php';
?>

<body>
	<div class="main" id="admincp">
		<div class="ui container section">
			<h2>Admin Control Panel</h2><br>
			<div class="ui center aligned grid" id="main_counters">
				<div class="four wide column">
					<div class="ui segment">
						<div class="label">
							<i class="ui icon users blue"></i>Total Users
						</div>
						<div class="value">
Example #13
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$QNA = new QNA();
$posts = $QNA->get_saved(USER_ID);
?>

<div class="tab-saved">
<?php 
foreach ($posts as $post) {
    ?>
	<div class="item" post-id="<?php 
    echo $post->id;
    ?>
">
		<div class="ui grid">
			<div class="fifteen wide column">
				<a href='/questions/question.php?id=<?php 
    echo $post->id;
    ?>
'><h4><?php 
    echo $post->title;
    ?>
</h4></a>
				<div class="time" id="post-date"><?php 
    echo $post->created;
    ?>
</div>
			</div>
			<div class="one wide column">
				<i class="remove large link icon" title="Remove this post" id="saved_remove"></i>
" >
	<button name="comment" id="subcomment" style="display:none;" class="ui blue submit disabled icon button">Submit</button>
</form>
<hr>
<div id="comments">
<?php 
if (count($comments) === 0) {
    echo "<span id=\"emptycmt\">There is nothing here yet, be the first to comment!</span>";
} else {
}
foreach ($comments as $comment) {
    $voted = QNA::has_voted($comment->id, USER_ID);
    $votes = Comment::get_votes($comment->id);
    $votes = $votes > 0 ? '+' . $votes : null;
    $self = $comment->uid === USER_ID;
    $rpsc = QNA::get_reports_count($comment->id) ?: false;
    $comment_date = $comment->created;
    $comment_edited_date = $comment->last_modified;
    if ($comment->last_modified > $comment->created) {
        $edited = "(edited <span class='datetime' title=\"{$comment_edited_date}\">{$comment_edited_date}</span>)";
    } else {
        $edited = "";
    }
    ?>
				<?php 
    if ($session->adminCheck()) {
        ?>
				<a style="color:red;" href="/admin/report.php?id=<?php 
        echo $comment->id;
        ?>
">
Example #15
0
<?php

// The view for the users
$pageTitle = "Stories";
$id = sanitize_id($_GET['id']) ?: null;
$QNA = new QNA();
if (!($q = $QNA->get_question($id))) {
    // if the id is not in the questions database, try to find it in the comment database.
    if ($q = Comment::getComment($id)) {
        $q = $q['post_id'];
        if ($q == $id) {
            Redirect::redirectTo('404');
        }
        Redirect::redirectTo(BASE_URL . "questions/question.php?id={$q}#{$id}");
    } else {
        Redirect::redirectTo('404');
    }
}
if ($q->status != 1 && !($session->adminCheck() || $session->userCheck($q->uid))) {
    Redirect::redirectTo('404');
}
$user = new User($q->uid);
$user = $user->user;
$self = $q->uid === USER_ID;
$voted = QNA::has_voted($id, USER_ID);
$votes_count = QNA::get_votes($id) ?: "0";
$post_date = $q->created;
$post_modified_date = $q->last_modified;
if ($q->last_modified > $q->created) {
    $edited = " (edited <span class='datetime' title=\"{$post_modified_date}\">{$post_modified_date}</span>)";
} else {
Example #16
0
			<button class="ui green button" id="new_sec">Add new section</button><br><br>
			<table class="ui definition selectable single line table">
				<thead>
					<tr>
						<th></th>
						<th>Name</th>
						<th>Acronym</th>
						<th>Questions</th>
						<th class="right aligned">Delete</th>
					</tr>
				</thead>
				<tbody>
					<?php 
foreach ($sections as $sec) {
    $i++;
    $qs_count = QNA::get_questions_count($sec['id']);
    ?>
					<tr id="<?php 
    echo $sec['id'];
    ?>
">
						<td><?php 
    echo $i;
    ?>
</td>
						<td><?php 
    echo $sec['title'];
    ?>
</td>
						<td><?php 
    echo $sec['acronym'];
Example #17
0
<?php

$post = new Post();
$QNA = new QNA();
$post->get_stream();
$feed = $post->getFeed();
usort($feed, 'date_compare');
//printX($feed);
//$feed = array_slice($feed, 0, 30); // limit the feed items to 30
if (empty($feed)) {
    echo "<p>There doesn't seem to be anything here, follow some users to see what they are up to!</p>";
} else {
}
foreach ($feed as $value) {
    switch ($value['type']) {
        case 'ac':
            $postID = $value['id'];
            $self = $value['u_id'] === $value['p_id'] ? true : false;
            $me = $value['p_id'] == USER_ID ? true : false;
            $to_self = $value['u_id'] === USER_ID ? true : false;
            $post_id = $value['id'];
            $poster_id = BASE_URL . "user/{$value['p_id']}/";
            $p_count = QNA::get_votes($postID) ?: "0";
            $commentsCount = $QNA->get_Qcomments($postID) ? count($QNA->get_Qcomments($postID)) : "0";
            ?>
			<div class="ui segment activity-view">
				<div class="header user-details">
					<div class="ui image mini">
						<a href="<?php 
            echo $poster_id;
            ?>
Example #18
0
            $report = QNA::report($PostID, $content, $user_id);
            if ($report === true) {
                die(json_encode(['status' => true, 'id' => $PostID]));
            } else {
                if ($report[1] == 1062) {
                    die(json_encode(['status' => false, 'id' => $PostID, 'err' => 1062]));
                } else {
                    die(json_encode(['status' => false, 'id' => $PostID, 'err' => $report[2]]));
                }
            }
        } else {
            $comment = Comment::getComment($PostID);
            if (!is_array($comment)) {
                die(json_encode(['status' => false, 'id' => $PostID, 'err' => 'Comment was not found.']));
            }
            $report = QNA::report($PostID, $content, $user_id);
            if ($report === true) {
                die(json_encode(['status' => true, 'id' => $PostID]));
            } else {
                if ($report[1] == 1062) {
                    die(json_encode(['status' => false, 'id' => $PostID, 'err' => 1062]));
                } else {
                    die(json_encode(['status' => false, 'id' => $PostID, 'err' => $report[2]]));
                }
            }
        }
        break;
    default:
        # code...
        break;
}
					<?php 
}
?>
				</div>
			</div>
			<h4>More stories by <a href="/user/<?php 
echo $q->uid;
?>
/"><?php 
echo $q->full_name;
?>
</a></h4>
			<div class="ui segment">
				<div class="ui relaxed divided list" id="sidebar-content">
					<?php 
$items = QNA::get_posts_by_user($q->uid, 5, true);
if (count($items) < 2) {
    echo "<p>This user doesn't have any other questions.</p>";
} else {
}
foreach ($items as $item) {
    ?>
					<?php 
    if ($q->id == $item->id) {
        continue;
    }
    ?>
						<div class="item">
							<div class="content">
								<a href="question.php?id=<?php 
    echo $item->id;
Example #20
0
 public static function PorQ($id)
 {
     $QNA = new QNA();
     $post = new self();
     if (is_object($QNA->get_question($id))) {
         return "q";
     } elseif (is_array($post->get_post($id, true))) {
         return "p";
     } elseif (is_array(Comment::getComment($id))) {
         return "c";
     } else {
         return false;
     }
 }
Example #21
0
?>
)</h3>
			<table class="ui red table">
				<thead>
					<tr>
						<th>Comment</th>
						<th>Owner</th>
						<th><a href="reports.php?cord=count">Reports count</a></th>
						<th><a href="reports.php?cord=date">Last reported</a></th>
						<th>Details</th>
					</tr>
				</thead>
				<tbody>
					<?php 
foreach ($c_reports as $rp) {
    $count = QNA::get_reports_count($rp->id);
    ?>
					<tr>
						<td><a href="/questions/question.php?id=<?php 
    echo $rp->id;
    ?>
"><?php 
    echo $rp->content;
    ?>
</a></td>
						<td><?php 
    echo View::user($rp->uid);
    ?>
</td>
						<td><?php 
    echo $count;
Example #22
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
$id = sanitize_id($_GET['id']) ?: null;
if (!$id) {
    $session->message("Invalid url.", "/404.php", "warning");
}
if ($id === 1 && !$session->adminCheck()) {
    Redirect::redirectTo();
}
$userg = new User();
$QNA = new QNA();
$user = $userg->get_user_info($id);
if (!$user) {
    $session->message("User was not found!", BASE_URL, 'danger');
}
$img_path = View::getPP($id);
$name = $user->full_name;
$username = $user->username;
$id = $user->id;
$email = $user->email;
$location = $user->address;
$gender = $user->gender;
$phoneNumber = $user->phoneNumber;
$register_date = $user->joined;
$birthDate = $user->birth_date;
$about = $user->about;
$website = $user->website;
$skype = $user->skype;
$twitter = $user->twitter;
$github = $user->github;