Jump to content

Question about modifying code


Recommended Posts

Hello All:


I am not very familiar with php, and need some advice about how to do something. Really appreciate a little advice.


I am making a forum with MODX, it has a module for forums called Discuss. Discuss has a built-in functionality to organize new topics into questions or discussions, regardless of the board a topic is in. So when you try to make a new topic it has got two buttons, question or discussion, and if you don't choose one it throws an error (its suppose to warn you but doesn't now).


I want to remove this function completely, not because of the error but just because its not suitable for my site which is not a support site. I don't care if the system considers all posts as questions, or as discussions, I just want the users to not have to choose and they can just post their topics, no buttons, no choice, and no error.


Removing the buttons is easy enough, but I need to change a little php to tell the system  to either not need this info, or just give it a default variable so that the user can post (I don't know the variable names right now but that is next I guess).


Anyway, here is the code which will probably be clearer than the above:

$discuss =& $modx->discuss;
$fields = $hook->getValues();

if (empty($fields['board'])) return $modx->error->failure($modx->lexicon('discuss.post_err_ns'));
$board = $modx->getObject('disBoard',$fields['board']);
if ($board == null) return false;

My first thought was to change the "If empty" line, and tell it, if empty then return (one of the two possible values). Then, everything would be ok, it seems to me.


But could I also just strip out the check for the variable completely? If I took out the three lines starting with $fields all the way to the "If empty" line, wouldn't that mean the check is gone and the post will post without concern that this value doesn't exist? Or would this set off the system somehow (as it presumably never contemplated that this value would not be there)?


Or, am I barking up the wrong tree here?


Really looking forward to some advice about this. Thanks in advance!  :happy-04:


Link to comment
Share on other sites

Wait I just saw something, the developer might have mixed up two names, the above code is in a piece called New Thread, but I noticed the message in there was wrong, it said it was about making a reply to a post.


So I checked the one called Reply to a Post, and found this:

* @var modX $modx
* @var Discuss $discuss
* @var fiHooks $hook
* @var string $submitVar
* @package discuss
$discuss =& $modx->discuss;
$fields = $hook->getValues();

if (empty($fields['post'])) return $modx->error->failure($modx->lexicon('discuss.post_err_ns'));
/** @var disPost $post */
$post = $modx->getObject('disPost',$fields['post']);
if ($post == null) return false;

/** @var disThread $thread */
$thread = $post->getOne('Thread');
if ($thread == null) return false;

The above code looks good, but it seems to focus on determining whether a board has been specified...this seems closer to what I want...maybe.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.