Ticket #746 (closed defect: invalid)

Opened 7 years ago

Last modified 1 month ago

blockform::classAvailable should use file_exists() instead of @include_once

Reported by: jsheth Assigned to: jsheth
Priority: normal Milestone: 0.4.8
Component: module - blocks Severity: normal
Keywords: Cc:

Description

The classAvailable method should use file_exists() instead of include_once SGL_BLK_DIR . '/' . $blockClass . '.php';

By using the @ symbol before include_once, all PHP errors are suppressed. If there are parse errors in the block that's being included, or in one of the files that it includes, just a blank page will be shown.

I spent hours trying to figure out why this blank page was being shown.

The old method looks like this:

function classAvailable($element)
    {
        SGL::logMessage("\n===classAvailable() is running===\n");
        if ($element) {
            $blockClass = $this->form->getElementValue('block[name]');
            include_once SGL_BLK_DIR . '/' . $blockClass . '.php';
            return class_exists($blockClass);
        }
        return true;
    }

You can replace it with:

function classAvailable($element)
    {
        SGL::logMessage("\n===classAvailable() is running===\n");
        if ($element) {
            $blockClass = $this->form->getElementValue('block[name]');
            $path = SGL_BLK_DIR . '/' . $blockClass . '.php';
            if ( file_exists($path) ){
                    include_once($path);
                    return class_exists($blockClass);
            }
            else{
                    return false;
            }
        }
        return true;
    }

I can attach a patch for this, as it would be good to have a fix for it in the stable version of Seagull. (Side note: I think things have changed in 0.6 ... BlockForm? is not used any more, because QuickForm? is not used in 0.6. I checked the block modules classes in version 0.6, but could not find any corressponding code that checks to see if the class for a block that is being added exists. Anyone have insight on this?)

Change History

03/15/06 16:50:00 changed by demian

sounds like a good suggestion - patches pls :-)

01/03/13 12:04:55 changed by demian

  • status changed from new to closed.
  • resolution set to invalid.