Jump to content

Where should I place this function? I'm looking for the "neatness" factor.


3raser

Recommended Posts

<?php
require('../structure/base.php');
require('../structure/forum.php');
require('../structure/forum.forum.php');
require('../structure/database.php');
require('../structure/user.php');

if($user->getRank($user->getUsername($_COOKIE['user'], 2)) > 2)
{
    //get selected threads and our action
    $threads = explode('-', $_GET['threads']);
    $action = $_GET['action'];

    //ACTION LIST
    //1 = HIDE
    //2 = LOCK
    //3 = MOVE
    //4 = AUTO-HIDE
    //5 = STICKY
    //6 = DELETE
    
    if($action == 3)
    {
        foreach($threads as $thread)
        {
            moveThread();
        }
        
        function moveThread($id, $moveTo)
        {
            //make sure it exists
            $thread = $database->processQuery("SELECT * FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true);

            if($database->getRowCount() == 1)
            {
                //array on a different line so it's not so messy
                $values = array($thread['parent'], $thread['title'], $thread['username'], $thread['date'], $thread['lastpost'], $thread['lastposter'], $moveTo.':'.$id, $thread['timestamp'], $thread['autohiding']);

                //thread exists, so let's continue and create a new thread where it was orgionally to indicate it has been moved
                $database->processQuery("INSERT INTO `threads` VALUES (null, ?, ?, '', ?, ?, '', ?, ?, '', '', '', '', '', ?, '0', ?, ?)", array($values), false);

                //now let's make the orgional thread be moved to the selected destination
                $database->processQuery("UPDATE `threads` SET `parent` = ? WHERE `id` = ? LIMIT 1", array($moveTo, $id), false);
            }
        }
    }
    else
    {

    }
}
else
{
    $base->redirect('index.php');
}
?>

 

I'm completely rewriting my website to more efficient/neater code, and I'm curious: the function in the above code moveThread() - should I leave it where it's at, implement the code within the function as a part of the foreach loop, or should I put the function at the very bottom of the page where it's in every scope?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
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.