In: Content Management Systems / Seditio / Seditio Tutorials

Global Forums Posts (core hack)

rather than have many topics, post one!

Print
Author: Dyllon
Submitted by: Dyllon   Date: 2008-04-20 15:40
Comments: (0)   Ratings:
No comments yet
Global Announcement Posts

This core hack will allow you to have one post, be posted globally on every forum. (useful for forum rules, important announcements, etc.)

Example : http://www.montagematerial.com/topic/57/Forum-Rules




Installing this hack:
as with any core hack, it is a good idea to make a backup just in case you mess up.

1. Run this sql code
Code:
ALTER TABLE sed_forum_topics ADD COLUMN global smallint(5) unsigned NOT NULL default '0';
2. /system/core/forums/forums.topics.inc.php Find
Code:
case 'announcement':

      sed_check_xg();
      $sql = sed_sql_query("UPDATE $db_forum_topics SET ft_sticky=1, ft_state=1 WHERE ft_id='$q'");
      sed_log("Announcement topic #".$q, 'for');
      header("Location: forums.php?m=topics&s=$s");
      exit;
      break;
After, ADD:
Code:
case 'global':

      sed_check_xg();
      $sql = sed_sql_query("UPDATE $db_forum_topics SET global=1, ft_sticky=1, ft_state=1 WHERE ft_id='$q'");
      sed_log("Global Announcement topic #".$q, 'for');
      header("Location: forums.php?m=topics&s=$s");
      exit;
      break;
3. /system/core/forums/forums.topics.inc.php Find
Code:
$mskin = sed_skinfile(array('forums', 'topics', $fs_category, $s));
$t = new XTemplate($mskin);
After, ADD:
Code:
$sql4 = sed_sql_query("SELECT * FROM $db_forum_topics WHERE global='1' $cond
   ORDER by global DESC, ft_".$o." ".$w."
   LIMIT $d, ".$cfg['maxtopicsperpage']);

while ($row4 = sed_sql_fetcharray($sql4))
   {
   $row4['ft_icon'] = 'posts';
   $row4['ft_postisnew'] = FALSE;
   $row4['ft_pages'] = '';
   $ft_num++;

   if ($row4['ft_mode']==1)
      { $row4['ft_title'] = "# ".$row4['ft_title']; }

   if ($row4['ft_movedto']>0)
      {
      $row4['ft_url'] = "forums.php?m=posts&q=".$row4['ft_movedto'];
      $row4['ft_icon'] = "<img src=\"skins/$skin/img/system/posts_moved.gif\" alt=\"\" />";
      $row4['ft_title']= $L['Moved'].": ".$row4['ft_title'];
      $row4['ft_lastpostername'] = "&nbsp;";
      $row4['ft_postcount'] = "&nbsp;";
      $row4['ft_replycount'] = "&nbsp;";
      $row4['ft_viewcount'] = "&nbsp;";
      $row4['ft_lastpostername'] = "&nbsp;";
      $row4['ft_lastposturl'] = "<a href=\"forums.php?m=posts&amp;q=".$row4['ft_movedto']."&amp;n=last#bottom\"><img src=\"skins/$skin/img/system/arrow-follow.gif\" alt=\"\" /></a> ".$L['Moved'];
      $row4['ft_timago'] = sed_build_timegap($row4['ft_updated'],$sys['now_offset']);
      }
   else
      {
      $row4['ft_title']= "Announcement: ".$row4['ft_title'];
      $row4['ft_url'] = "forums.php?m=posts&amp;q=".$row4['ft_id'];
      $row4['ft_lastposturl'] = ($usr['id']>0 && $row4['ft_updated'] > $usr['lastvisit']) ? "<a href=\"forums.php?m=posts&amp;q=".$row4['ft_id']."&amp;n=unread#unread\"><img src=\"skins/$skin/img/system/arrow-unread.gif\" alt=\"\" /></a>" : "<a href=\"forums.php?m=posts&amp;q=".$row4['ft_id']."&amp;n=last#bottom\"><img src=\"skins/$skin/img/system/arrow-follow.gif\" alt=\"\" /></a>";
      $row4['ft_lastposturl'] .= @date($cfg['formatmonthdayhourmin'], $row4['ft_updated'] + $usr['timezone'] * 3600);
      $row4['ft_timago'] = sed_build_timegap($row4['ft_updated'],$sys['now_offset']);
      $row4['ft_replycount'] = $row4['ft_postcount'] - 1;

      if ($row4['ft_updated']>$usr['lastvisit'] && $usr['id']>0)
         {
         $row4['ft_icon'] .= '_new';
         $row4['ft_postisnew'] = TRUE;
         }

      if ($row4['ft_postcount']>=$cfg['hottopictrigger'] && !$row4['ft_state'] && !$row4['ft_sticky'])
         { $row4['ft_icon'] = ($row4['ft_postisnew']) ? 'posts_new_hot' : 'posts_hot'; }
      else
         {
         if ($row4['ft_sticky'])
            { $row4['ft_icon'] .= '_sticky'; }

         if ($row4['ft_state'])
            { $row4['ft_icon'] .= '_locked'; }
         }

      $row4['ft_icon'] = "<img src=\"skins/$skin/img/system/".$row4['ft_icon'].".gif\" alt=\"\" />";
      $row4['ft_lastpostername'] = sed_build_user($row4['ft_lastposterid'], sed_cc($row4['ft_lastpostername']));
      }

   $row4['ft_firstpostername'] = sed_build_user($row4['ft_firstposterid'], sed_cc($row4['ft_firstpostername']));

   if ($row4['ft_poll']>0)
      { $row4['ft_title'] = $L['Poll'].": ".$row4['ft_title']; }

   if ($row4['ft_postcount']>$cfg['maxtopicsperpage'])
      {
      $row4['ft_maxpages'] = ceil($row4['ft_postcount'] / $cfg['maxtopicsperpage']);
      $row4['ft_pages'] = $L['Pages'].":";
      for ($a = 1; $a <= $row4['ft_maxpages']; $a++)
         {
         $row4['ft_pages'] .= (is_int($a/5) || $a<10 || $a==$row4['ft_maxpages']) ? " <a href=\"".$row4['ft_url']."&amp;d=".($a-1) * $cfg['maxtopicsperpage']."\">".$a."</a>" : '';
         }
   }

   $t-> assign(array(
      "FORUMS_TOPICS_GLOBAL_ROW_ID" => $row4['ft_id'],
      "FORUMS_TOPICS_GLOBAL_ROW_STATE" => $row4['ft_state'],
      "FORUMS_TOPICS_GLOBAL_ROW_ICON" => $row4['ft_icon'],
      "FORUMS_TOPICS_GLOBAL_ROW_TITLE" => sed_cc($row4['ft_title']),
      "FORUMS_TOPICS_GLOBAL_ROW_CREATIONDATE" => @date($cfg['formatmonthdayhourmin'], $row4['ft_creationdate'] + $usr['timezone'] * 3600),
      "FORUMS_TOPICS_GLOBAL_ROW_UPDATED" => $row4['ft_lastposturl'],
      "FORUMS_TOPICS_GLOBAL_ROW_TIMEAGO" => $row4['ft_timago'],
      "FORUMS_TOPICS_GLOBAL_ROW_POSTCOUNT" => $row4['ft_postcount'],
      "FORUMS_TOPICS_GLOBAL_ROW_REPLYCOUNT" => $row4['ft_replycount'],
      "FORUMS_TOPICS_GLOBAL_ROW_VIEWCOUNT" => $row4['ft_viewcount'],
      "FORUMS_TOPICS_GLOBAL_ROW_FIRSTPOSTER" => $row4['ft_firstpostername'],
      "FORUMS_TOPICS_GLOBAL_ROW_LASTPOSTER" => $row4['ft_lastpostername'],
      "FORUMS_TOPICS_GLOBAL_ROW_URL" => $row4['ft_url'],
      "FORUMS_TOPICS_GLOBAL_ROW_PAGES" => $row4['ft_pages'],
      "FORUMS_TOPICS_GLOBAL_ROW_MAXPAGES" => $row4['ft_maxpages'],
      "FORUMS_TOPICS_GLOBAL_ROW_ODDEVEN" => sed_build_oddeven($ft_num),
      "FORUMS_TOPICS_GLOBAL_ROW" => $row,
      ));


   $t->parse("MAIN.FORUMS_GLOBAL.FORUMS_TOPICS_GLOBAL_ROW");
   }

$t->parse("MAIN.FORUMS_GLOBAL");
4. /system/core/forums/forums.topics.inc.php Find
Code:
case 'clear':

      sed_check_xg();
      sed_log("Resetted topic #".$q, 'for');
      $sql = sed_sql_query("UPDATE $db_forum_topics SET ft_sticky=0, ft_state=0, ft_mode=0 WHERE ft_id='$q'");
      header("Location: forums.php?m=topics&s=$s");
      exit;
      break;
REPLACE WITH:
Code:
case 'clear':

      sed_check_xg();
      sed_log("Resetted topic #".$q, 'for');
      $sql = sed_sql_query("UPDATE $db_forum_topics SET ft_sticky=0, ft_state=0, global=0, ft_mode=0 WHERE ft_id='$q'");
      header("Location: forums.php?m=topics&s=$s");
      exit;
      break;
5. /system/core/forums/forums.posts.inc.php Find (Notice: file has changed)
Code:
if ($usr['isadmin'])
   {
   $adminoptions = "<form id=\"movetopic\" action=\"forums.php?m=topics&amp;a=move&amp;".sed_xg()."&amp;s=".$s."&amp;q=".$q."\" method=\"post\">";
   $adminoptions .= $L['Topicoptions']." : <a href=\"forums.php?m=topics&amp;a=bump&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Bump'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=lock&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Lock'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=sticky&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Makesticky'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=announcement&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Announcement'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=private&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Private']." (#)";
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=clear&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Default'];
   $adminoptions .= "</a> &nbsp; ".$L['Delete'].":[<a href=\"forums.php?m=topics&amp;a=delete&amp;".sed_xg()."&amp;s=".$s."&amp;q=".$q."\">x</a>] ".$movebox."</form>";
   }
REPLACE WITH:
Code:
if ($usr['isadmin'])
   {
   $adminoptions = "<form id=\"movetopic\" action=\"forums.php?m=topics&amp;a=move&amp;".sed_xg()."&amp;s=".$s."&amp;q=".$q."\" method=\"post\">";
   $adminoptions .= $L['Topicoptions']." : <a href=\"forums.php?m=topics&amp;a=bump&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Bump'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=lock&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Lock'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=sticky&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Makesticky'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=announcement&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Announcement'];
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=global&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">Global Announcement";
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=private&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Private']." (#)";
   $adminoptions .= "</a> &nbsp; <a href=\"forums.php?m=topics&amp;a=clear&amp;".sed_xg()."&amp;q=".$q."&amp;s=".$s."\">".$L['Default'];
   $adminoptions .= "</a> &nbsp; ".$L['Delete'].":[<a href=\"forums.php?m=topics&amp;a=delete&amp;".sed_xg()."&amp;s=".$s."&amp;q=".$q."\">x</a>] ".$movebox."</form>";
   }



Ok now that all of the file editing is finished, you now have to implement it into your tpl file.

6. /skins/YOURSKIN/forums.topics.tpl ADD
Code:
<!-- BEGIN: FORUMS_GLOBAL -->

<table class="cells">

   <tr>
      <td colspan="2" class="coltop">
      {FORUMS_TOPICS_TITLE_TOPICS} / {FORUMS_TOPICS_TITLE_STARTED}</td>
      <td class="coltop" style="width:176px;">
      {FORUMS_TOPICS_TITLE_LASTPOST}</td>
      <td class="coltop" style="width:56px;">
      {FORUMS_TOPICS_TITLE_POSTS}</td>
      <td class="coltop" style="width:56px;">
      {FORUMS_TOPICS_TITLE_VIEWS}</td>

   </tr>

<!-- BEGIN: FORUMS_TOPICS_GLOBAL_ROW -->

   <tr>
      <td style="width:32px;" class="centerall {FORUMS_TOPICS_GLOBAL_ROW_ODDEVEN}">
      {FORUMS_TOPICS_GLOBAL_ROW_ICON}
      </td>

      <td class="{FORUMS_TOPICS_GLOBAL_ROW_ODDEVEN}">
      <strong><a href="{FORUMS_TOPICS_GLOBAL_ROW_URL}">{FORUMS_TOPICS_GLOBAL_ROW_TITLE}</a></strong><br />
      {FORUMS_TOPICS_GLOBAL_ROW_PAGES} &nbsp; {FORUMS_TOPICS_GLOBAL_ROW_CREATIONDATE} : {FORUMS_TOPICS_GLOBAL_ROW_FIRSTPOSTER}
      </td>


      <td class="centerall {FORUMS_TOPICS_GLOBAL_ROW_ODDEVEN}">
      {FORUMS_TOPICS_GLOBAL_ROW_UPDATED} {FORUMS_TOPICS_GLOBAL_ROW_LASTPOSTER}<br />
      {FORUMS_TOPICS_GLOBAL_ROW_TIMEAGO}</span>
      </td>

      <td class="centerall {FORUMS_TOPICS_GLOBAL_ROW_ODDEVEN}">
      {FORUMS_TOPICS_GLOBAL_ROW_POSTCOUNT}
      </td>

      <td class="centerall {FORUMS_TOPICS_GLOBAL_ROW_ODDEVEN}">
      {FORUMS_TOPICS_GLOBAL_ROW_VIEWCOUNT}
      </td>

   </tr>

<!-- END: FORUMS_TOPICS_GLOBAL_ROW -->

</table>


<!-- END: FORUMS_GLOBAL -->



Now all is in place, and it is up to you to make it work. All you have to do is open up a topic that you would like to be announced globally, and click Global Announcement. ta-da, you have an announcement that will be shown in every forum.