Jump to content

Recommended Posts

/*
     * @METHOD  checkExistence
     * @DESC    check if the thread exists
     */
    
    public function checkExistence($id)
    {
        $thread = $database->processQuery("SELECT * FROM `threads` WHERE `id` = ? LIMIT 1", array($id), false);
        return ($database->getRowCount() == 1) ? $x = true : $x = false;
    }
    
    
    /*
     * @METHOD  canView
     * @DESC    checks if the user has permissions to see thread
     */
    
    public function canView($id, $username, $powerLevel)
    {
        //extract thread details
        $thread = $database->processQuery("SELECT `parent`,`hidden` FROM `threads` WHERE `id` = ? LIMIT 1", array($id), true);
        
        if($database->getRowCount() == 1)
        {
            $canSee = true;
            
            //get the parent's type
            $parent = $database->processQuery("SELECT `type` FROM `forums` WHERE `id` = ? LIMIT 1", array($thread[0]['parent']), true);
            
            if($parent[0]['type'] == 3 && ($username != $thread[0]['username'] && $powerLevel < 3))
            {
               $canSee = false; 
            }
            
            if($thread[0]['hidden'] == 1 && $powerLevel < 3)
            {
                $canSee = false;
            }
            
            return false;
        }
        
        return false;
    }

 

And then I preform the checks here:

 

//preform basic checks
if($thread->checkExistence($_GET['id']) == false) $base->redirect('index.php');
if($thread->canView($_GET['id'], $username, $rank) == false) $base->redirect('index.php');

 

But as you can see in the canView() function, it returns false if the thread is not found. So, should I remove the checkExistence() function, leave the code as is, or just remove the if thread exists check from canView()?

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.