From 9bae4628a0e94e33024930887980ce118f827c2a Mon Sep 17 00:00:00 2001 From: PioDer Date: Sun, 15 Feb 2015 17:27:06 +0100 Subject: [PATCH] added feature: stick/unstick topic --- config.php | 4 ++++ inc/controllers/MainController.class.php | 21 +++++++++++++++++++++ inc/models/ForumsModel.class.php | 2 +- inc/models/PostsModel.class.php | 9 ++++++++- templates/images/stick.gif | Bin 0 -> 1061 bytes templates/images/unstick.gif | Bin 0 -> 1099 bytes templates/styles.css | 2 +- templates/viewforum.tpl.php | 3 ++- templates/viewtopic.tpl.php | 3 +++ 9 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 templates/images/stick.gif create mode 100644 templates/images/unstick.gif diff --git a/config.php b/config.php index a2aeb21..e23c2d5 100644 --- a/config.php +++ b/config.php @@ -17,4 +17,8 @@ define('FORUM_PATH', '/uf2'); define('HTTP_PORT', 81); define('HTTPS_PORT', 443); define('USE_HTTPS', true); + +define('RANDOM_STRING', 'oVadvzFdxAezvuknUNXdQLoQMkQwrQuAbFPYfLIKfPWzbciVNkOfTWAdWKXexYZpZycXoxJmAXkRGsoZzwijGUQcdtYTwxtzWLiQjMpfAQgMLUeoTvkYUMmxvVPLmKJDsCFwhqWIGBLAqRnDnUOwCTEKvLvdzOyc'); +define('SALT_LENGTH', 20); + ?> diff --git a/inc/controllers/MainController.class.php b/inc/controllers/MainController.class.php index 45117a2..c3fb9a5 100644 --- a/inc/controllers/MainController.class.php +++ b/inc/controllers/MainController.class.php @@ -164,6 +164,7 @@ class MainController extends Controller { case 'deletetopic': case 'locktopic': + case 'sticktopic': case 'movetopic': $t = $this->getModel('PostsModel')->getTopic($_GET['id']); @@ -232,6 +233,19 @@ class MainController extends Controller } $lockv = true; break; + case 'sticktopic': + if ($t['topic_sticky'] == false) + { + $this->getModel('PostsModel')->stickTopic($_GET['id']); + $this->getView('MainView')->forum_message('Topic sticked. Redirecting...', buildURL('index.php?mode=viewtopic&id='.$_GET['id'])); + } + else + { + $this->getModel('PostsModel')->stickTopic($_GET['id'], false); + $this->getView('MainView')->forum_message('Topic unsticked. Redirecting...', buildURL('index.php?mode=viewtopic&id='.$_GET['id'])); + } + $lockv = true; + break; case 'movetopic': if ($this->getModel('ForumsModel')->getForum($_POST['forum_id']) == null) $this->getView('MainView')->forum_message('Forum does not exist!', buildURL('index.php?mode=viewtopic&id='.$_GET['id'])); @@ -251,6 +265,7 @@ class MainController extends Controller { case 'deletetopic': case 'locktopic': + case 'sticktopic': case 'movetopic': $this->forward(buildURL('index.php?mode=viewtopic&id='.$_GET['id'])); break; @@ -276,6 +291,12 @@ class MainController extends Controller else $this->getView('MainView')->confirm_action('Do you want unlock topic #'.$_GET['id'].'?'); break; + case 'sticktopic': + if ($t['topic_sticky'] == false) + $this->getView('MainView')->confirm_action('Do you want stick topic #'.$_GET['id'].'?'); + else + $this->getView('MainView')->confirm_action('Do you want unstick topic #'.$_GET['id'].'?'); + break; case 'movetopic': $this->getView('MainView')->putExistingModel('PostsModel', $this->getModel('PostsModel')); $this->getView('MainView')->move_topic(); diff --git a/inc/models/ForumsModel.class.php b/inc/models/ForumsModel.class.php index e22edb7..30ed5a8 100644 --- a/inc/models/ForumsModel.class.php +++ b/inc/models/ForumsModel.class.php @@ -45,7 +45,7 @@ class ForumsModel extends Model public function getTopics($forum_id) { - $out = $this->select(TOPICS_VIEW, '*', 'forum_id=\''.$forum_id.'\'', 'lastpost_post_id DESC'); + $out = $this->select(TOPICS_VIEW, '*', 'forum_id=\''.$forum_id.'\'', 'sticky DESC,lastpost_post_id DESC'); if (count($out) > 0) return $out; else diff --git a/inc/models/PostsModel.class.php b/inc/models/PostsModel.class.php index b78c5c2..7b8552a 100644 --- a/inc/models/PostsModel.class.php +++ b/inc/models/PostsModel.class.php @@ -18,7 +18,7 @@ class PostsModel extends Model { $query = ' SELECT - t.topic_id as topic_id, t.title as topic_title, t.locked as topic_locked, t.forum_id as forum_id, f.name as forum_name, f.locked as forum_locked, pc.post_count as post_count + t.topic_id as topic_id, t.title as topic_title, t.sticky as topic_sticky, t.locked as topic_locked, t.forum_id as forum_id, f.name as forum_name, f.locked as forum_locked, pc.post_count as post_count FROM '.TOPICS_TABLE.' t LEFT JOIN '.FORUMS_TABLE.' f ON f.forum_id = t.forum_id LEFT JOIN '.TOPICS_PC_VIEW.' pc ON pc.topic_id = t.topic_id @@ -82,6 +82,13 @@ class PostsModel extends Model $this->db->query($query); } + public function stickTopic($topic_id, $sticky = true) + { + $query = 'UPDATE '.TOPICS_TABLE.' SET sticky=\''.$sticky.'\' WHERE topic_id=\''.$topic_id.'\';'; + + $this->db->query($query); + } + public function moveTopic($topic_id, $forum_id) { $query = 'UPDATE '.TOPICS_TABLE.' SET forum_id=\''.$forum_id.'\' WHERE topic_id=\''.$topic_id.'\';'; diff --git a/templates/images/stick.gif b/templates/images/stick.gif new file mode 100644 index 0000000000000000000000000000000000000000..a1073bb7c76487d9116376d436b2aa7df2468416 GIT binary patch literal 1061 zcmZ?wbhEHb6lM@&_|CwvVebEy-v82G|1CrQ&+hoIE46>ylK&HG|Hqa7XVCiTnDl?` zvi}FS{6DzvKLbP8o|XTL8~+z%|3A9difAPfsyEpt-bNzpA z?|&h?|IAkZ85F-Nx{c4%Z| z;cz(cV1WaRoRCJw4u{4D21b#J8wCc=O14l!{XXge^wu)aR3JV*XxCQh~Y$_ZZgV|T5*Nj}bEqiL~V z!{p^HYqj~+B0exQFwf+FB&D#R@r476tkjWGf$h4D%wje^cNZ*hX5GurAz{Gq;6MY5 zIJ?${UkMw}Gxe}*L=*@dV%W(hr^9+6;=qwcXG!J*4h;@0JgXRa91J#SWgn0-iBM=@ zJn)J`mM!hWfkXy&ehvYS83_*$#Ghq1XOUoNRCZ#NWy|<*V5i2pm*PBJOgtP6)&Mz! B@jd_m literal 0 HcmV?d00001 diff --git a/templates/images/unstick.gif b/templates/images/unstick.gif new file mode 100644 index 0000000000000000000000000000000000000000..e78a19d7772ebd921d71de6b6a726bc5199ca394 GIT binary patch literal 1099 zcmeH`*G`iG07m~Z6b%lFAPPo^Bw|G^)Tn5TNTFDTiiirxXqh4iv}_S+X&I%A0;ROb z9)g3>GGx=@U^syoH5!8pXPg&G41VfUc;m@=f|DFqCS!*KXBlBkd?$$YD|&5A`Zk#M zQ&tXaG#j*CHMD8<@Md$(77HzP%?Qo%I-Po-L3`-t@brk&>toJuyD zBQFK{r%{lK!ZVPjq3A4%(^0~QOn}l1$b~2qL6He%7Rs}6E(aB2ROX^eg6cfffB3v=d`p81Kf!72NE>tzO*j!<~Li z4q<8-)0+SO%K}z&dL)7XVN3ks?-L6RKw$oHoQq2i+0t3${bsL7lWr#`)b-gci)|6N zq;n%|HzP;>#~$T0BVTDBsAeg_oQK;bnT9)d;CeAOx6a^Lc=dwdZMA}W-mjkN^e|h=@2xUtgRCnkaw06TPL['topics_list']); $i++) { echo '
'."\n"; - echo "\t\t\t".''."\n"; + $sticky = ($this->TPL['topics_list'][$i]['sticky']) ? 'Sticky: ' : ''; + echo "\t\t\t".''."\n"; echo "\t\t\t".'
'; if ($this->TPL['topics_list'][$i]['user_id'] != null) echo ''.$this->colorRank($this->TPL['topics_list'][$i]['user_nick'], $this->TPL['topics_list'][$i]['user_rank']).''; diff --git a/templates/viewtopic.tpl.php b/templates/viewtopic.tpl.php index 80cc530..c98cf36 100755 --- a/templates/viewtopic.tpl.php +++ b/templates/viewtopic.tpl.php @@ -108,6 +108,9 @@