We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Fix for the forum privacy issue | Forum

dave Leader
dave Oct 22 '13

Issue - when you select private forum, those who can view can still post.  There is no var switch for private and the core var for $isAdmin is not present.


Solution:

1. Add var flag for private forum in php  file.

 

2. Since the customary core $isAdmin var is not present or assigned in php file then create a new var to flag that user is admin or not.

 

3. Assign both new vars to smarty in php file.

 

4. added another IF filter to html file that if the forum is private then it checks to see if the flags for moderator or owner or admin.  If moderator or owner or admin flag is set then the post form will appear as normal.

 

If  the moderator or owner or admin flag is not set then the post form will not display and a message "Not authorized to post replies" will appear in place of the post form.


If the forum is not private the forum and all features will work as normal.


Below i will take you through the code changes as well as attach a copy of the original 1.53 version files that have been modified with this change.  Oxwall developers may want to add this to the OX core but this is at your discretion of course.


Puplic - Important: these changes were done on a UNMODIFIED original 1.53 file so the line numbers may not be what you have if you have applied any mods.  Also you need to follow this in order, the reason for this is that as you add mod code to the top of the file the line numbers below will increase of course and so those are the line numbers i used.  If you do this any other way but top to bottom the line numbers will not be the same as what you have.


Lets begin: 


First we have to set the new vars and assign them via smarty.


Open ow_plugins/forum/controllers/topic.php


1. on line 137 you will find this code:


if ( $forumGroup->isPrivate )
{

 

1a. Right above that code you will add this code:


// initialize var

$pvtforum = 0;

$pvtadmin = 0;


so now it looks like this:


         // initialize var
         $pvtforum = 0;

         $pvtadmin = 0;

 

        if ( $forumGroup->isPrivate )
        {

 

1b. now right after that code above you add this code


          // add special mod for privacy setting
           $pvtforum = 1;
              if( OW::getUser()->isAdmin())
              {
               $pvtadmin = 1;
               }
          //end mod

1c. so now the whole change looks like this:


         //initialize var
         $pvtforum = 0;
        $pvtadmin = 0;

 

        if ( $forumGroup->isPrivate )
        {
    
          // add special mod for privacy setting
           $pvtforum = 1;
              if( OW::getUser()->isAdmin())
              {
               $pvtadmin = 1;
               }
          //end mod

 

2. scroll down to line 170 and you will find this code:


$this->assign('isHidden', $isHidden);


2a.  after that code add this code:


// priv mod
$this->assign('pvtforum', $pvtforum);
$this->assign('pvtadmin', $pvtadmin);
//end mod


2b. so now the whole mod looks like this:


         $this->assign('isHidden', $isHidden);

 

         // priv mod
         $this->assign('pvtforum', $pvtforum);
         $this->assign('pvtadmin', $pvtadmin);
        //end mod


3. You are done with this file, save it...

 

4. Now open  ow_plugins/forum/views/controllers/topic_index.html

 

The Objective is to wrap the forum with an IF statement

 

4a. on line 160 you will find this code:

 

   {elseif ( !$isHidden && ($canPost || $isModerator) ) || ( $isHidden && $canPost ) }

 

4b. after that code add this code:

 

<!-- start mod here -->
     {if $pvtforum && (!isModerator || !isOwner || !$pvtadmin)}
        <span>Not Authorized To Post Replies</span>      
     {else}
<!-- end mod -->

 

4c. on line 181 you will see this code:

 

  {/form}

 

4d.  after that code add this code:

 

<!-- close mod if -->
   {/if}
<!-- end mod -->

 

 

4e.  So the whole change will look like this now:

 

    {elseif ( !$isHidden && ($canPost || $isModerator) ) || ( $isHidden && $canPost ) }
 
 <!-- start mod here -->
     {if $pvtforum && (!isModerator || !isOwner || !$pvtadmin)}
        <span>Not Authorized To Post Replies</span>      
     {else}
     <!-- end mod --> 
 
        {form name='add-post-form'}
            {block_decorator name='box' iconClass='ow_ic_write' langLabel='forum+add_post_title' addClass='ow_stdmargin'}
                {input name='text' class="ow_smallmargin"}
                {error name='text'}<br />
                {if $enableAttachments}
                <span class="ow_forum_attachment_icon ow_ic_attach">&nbsp;</span>
                <a href="javascript://" id="toggle_attach_link">{text key='forum+attach_files'}</a><br /><br />
                <div class="ow_hidden ow_smallmargin" id="attach_file_inputs">
                    {input name='attachments'}
                </div>
                {/if}
                <div class="clearfix"><div class="ow_right">{submit name='submit' class='ow_positive'}</div></div>
            {/block_decorator}
        {/form}
  
<!-- close mod if -->
   {/if}
<!-- end mod -->

 

4f.  you are done so save the file..

 

now clear your site cache and browser cache and take a look at your forum. If you have a private forum go to it.  If you are admin or moderator or owner it will look quite normal, if you are not either of these you will not have an area to post in and the only thing that should show is a message that you are not authorized to post replies and the subscription link.

 

good job..

 

The files attached are txt extentions. 

The topic_index.txt should be renamed to topic_index.html

The topic.txt should be renamed to topic.php

 

I hope this helps someone.... 
 

The Forum post is edited by dave Oct 22 '13
Attachments:
  topic.txt (39.33Kb)
  topic_index.txt (8.26Kb)
dave Leader
dave Nov 10 '13

i did make one tiny error well not really but i didnt explain well.. 

 

{if $pvtforum && (isModerator || !isOwner || !$pvtadmin)}

will keep even your mods from being able to post and

 

{if $pvtforum && (!isModerator || !isOwner || !$pvtadmin)}

 

will allow your mods to post in that private forum.