thank you - attached
<?php
namespace CODOF\Forum;
class Topic extends Forum {
protected $db;
public $ajax = false;
public $new_topic_ids = array();
public $new_replies = array();
public $tags = array();
public function __construct($db) {
$this->db = $db;
}
public function get_topics($cat_id, $page = 1) {
$cat_id = (int) $cat_id;
$topics = array();
$num_posts = \CODOF\Util::get_opt("num_posts_cat_topics");
$from = ($page - 1) * $num_posts;
$qry = 'SELECT p.post_id,p.omessage AS message, p.post_created, r.rid, u.id, u.name AS name, u.avatar, '
. 't.topic_id, t.uid, t.no_posts, t.no_views, t.title, t.topic_created,last_post_id, '
. 't.last_post_name AS lname, t.last_post_uid AS luid, t.last_post_time AS lpost_time,'
. 't.topic_status '
. 'FROM ' . PREFIX . 'codo_topics AS t '
. 'LEFT JOIN ' . PREFIX . 'codo_posts AS p ON (t.post_id=p.post_id AND p.post_status=1) '
. 'LEFT JOIN ' . PREFIX . 'codo_users AS u ON u.id=p.uid '
. 'LEFT JOIN ' . PREFIX . 'codo_user_roles AS r ON u.id=r.uid AND r.is_primary=1 '
. 'WHERE t.cat_id=' . $cat_id
. ' AND ('
. ' t.topic_status=' . Forum::APPROVED . ' OR'
. ' t.topic_status=' . Forum::APPROVED_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY . ' OR'
. ' t.topic_status=' . Forum::STICKY_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY_CLOSED . ' ) AND '
. $this->getViewTopicPermissionConditions()
. 'ORDER BY t.topic_status DESC, t.last_post_time DESC LIMIT ' . $num_posts . ' OFFSET ' . $from;
$stmt = $this->db->query($qry);
if ($stmt) {
return $stmt->fetchAll();
}
return $topics;
}
public function getTaggedTopics($tag, $from = 0) {
$_topics = array();
$num_posts = \CODOF\Util::get_opt("num_posts_all_topics");
$qry = 'SELECT p.post_id, p.omessage AS message, p.post_created, r.rid, u.id, u.name as name, u.avatar, c.cat_img, c.cat_alias,'
. 't.topic_id, t.uid, t.title, t.no_posts, t.no_views, t.last_post_time, t.last_post_uid, '
. 't.last_post_name AS last_post_name, t.topic_created, t.cat_id, last_post_id,t.topic_status '
. 'FROM codo_topics AS t INNER JOIN codo_tags as g ON g.topic_id=t.topic_id '
. 'LEFT JOIN codo_posts AS p ON (t.post_id=p.post_id AND p.post_status=1)'
. 'LEFT JOIN codo_users AS u ON u.id=p.uid '
. 'LEFT JOIN codo_categories AS c ON c.cat_id=t.cat_id '
. 'LEFT JOIN ' . PREFIX . 'codo_user_roles AS r ON u.id=r.uid AND r.is_primary=1 '
. ' WHERE ('
. ' t.topic_status=' . Forum::APPROVED . ' OR'
. ' t.topic_status=' . Forum::APPROVED_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY . ' OR'
. ' t.topic_status=' . Forum::STICKY_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY_CLOSED . ' ) AND '
. $this->getViewTopicPermissionConditions()
. ' AND g.tag_name=' . $this->db->quote($tag)
. ' ORDER BY t.last_post_time DESC LIMIT ' . $num_posts . ' OFFSET ' . $from;
$ans = $this->db->query($qry);
if ($ans) {
$topics = $ans->fetchAll();
$_topics = $this->gen_topic_arr_all_topics($topics);
}
return $_topics;
}
thank you - attached
```
<?php
/*
* @CODOLICENSE
*
*
* issue system
*
* users can view own content
* users cannot view others content
*
* moderators/admin -> full priveleges
*
*
* premium member system
*
* role A can access forum B
*
*
*
*
*/
namespace CODOF\Forum;
class Topic extends Forum {
//put your code here
protected $db;
public $ajax = false;
public $new_topic_ids = array();
public $new_replies = array();
public $tags = array();
public function __construct($db) {
$this->db = $db;
}
//TODO: make this a little more reusable
public function get_topics($cat_id, $page = 1) {
//$t = microtime(true);
$cat_id = (int) $cat_id;
$topics = array();
$num_posts = \CODOF\Util::get_opt("num_posts_cat_topics");
$from = ($page - 1) * $num_posts;
//username , title, topic created, no of replies,
$qry = 'SELECT p.post_id,p.omessage AS message, p.post_created, r.rid, u.id, u.name AS name, u.avatar, '
. 't.topic_id, t.uid, t.no_posts, t.no_views, t.title, t.topic_created,last_post_id, '
. 't.last_post_name AS lname, t.last_post_uid AS luid, t.last_post_time AS lpost_time,'
. 't.topic_status '
. 'FROM ' . PREFIX . 'codo_topics AS t '
. 'LEFT JOIN ' . PREFIX . 'codo_posts AS p ON (t.post_id=p.post_id AND p.post_status=1) '
. 'LEFT JOIN ' . PREFIX . 'codo_users AS u ON u.id=p.uid '
. 'LEFT JOIN ' . PREFIX . 'codo_user_roles AS r ON u.id=r.uid AND r.is_primary=1 '
. 'WHERE t.cat_id=' . $cat_id
. ' AND ('
. ' t.topic_status=' . Forum::APPROVED . ' OR'
. ' t.topic_status=' . Forum::APPROVED_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY . ' OR'
. ' t.topic_status=' . Forum::STICKY_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY_CLOSED . ' ) AND '
. $this->getViewTopicPermissionConditions()
. 'ORDER BY t.topic_status DESC, t.last_post_time DESC LIMIT ' . $num_posts . ' OFFSET ' . $from;
$stmt = $this->db->query($qry);
if ($stmt) {
return $stmt->fetchAll();
}
return $topics;
}
public function getTaggedTopics($tag, $from = 0) {
$_topics = array();
//$t = microtime(true);
$num_posts = \CODOF\Util::get_opt("num_posts_all_topics");
//username , title, topic created, no of replies,
$qry = 'SELECT p.post_id, p.omessage AS message, p.post_created, r.rid, u.id, u.name as name, u.avatar, c.cat_img, c.cat_alias,'
. 't.topic_id, t.uid, t.title, t.no_posts, t.no_views, t.last_post_time, t.last_post_uid, '
. 't.last_post_name AS last_post_name, t.topic_created, t.cat_id, last_post_id,t.topic_status '
. 'FROM codo_topics AS t INNER JOIN codo_tags as g ON g.topic_id=t.topic_id '
. 'LEFT JOIN codo_posts AS p ON (t.post_id=p.post_id AND p.post_status=1)'
. 'LEFT JOIN codo_users AS u ON u.id=p.uid '
. 'LEFT JOIN codo_categories AS c ON c.cat_id=t.cat_id '
. 'LEFT JOIN ' . PREFIX . 'codo_user_roles AS r ON u.id=r.uid AND r.is_primary=1 '
. ' WHERE ('
. ' t.topic_status=' . Forum::APPROVED . ' OR'
. ' t.topic_status=' . Forum::APPROVED_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY . ' OR'
. ' t.topic_status=' . Forum::STICKY_CLOSED . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY . ' OR'
. ' t.topic_status=' . Forum::STICKY_ONLY_CATEGORY_CLOSED . ' ) AND '
. $this->getViewTopicPermissionConditions()
. ' AND g.tag_name=' . $this->db->quote($tag)
. ' ORDER BY t.last_post_time DESC LIMIT ' . $num_posts . ' OFFSET ' . $from;
$ans = $this->db->query($qry);
//echo $qry;
if ($ans) {
$topics = $ans->fetchAll();
$_topics = $this->gen_topic_arr_all_topics($topics);
}
//echo " <br/>get_all_topics() ";
//echo microtime(true) - $t;
return $_topics;
}
```
edited Nov 28 '16 at 6:11 pm