Exemple #1
0
/**
 * Include a script, unless it has caused a fatal error.
 * Using this function allows gpEasy to handle fatal errors that are thrown by the included php scripts
 *
 * @param string $file The full path of the php file to include
 * @param string $include_variation Which variation or adaptation of php's include() function to use (include,include_once,include_if, include_once_if, require ...)
 * @param array List of global variables to set
 */
function IncludeScript($file, $include_variation = 'include_once', $globals = array())
{
    $exists = file_exists($file);
    //check to see if it exists
    $include_variation = str_replace('_if', '', $include_variation, $has_if);
    if ($has_if && !$exists) {
        return;
    }
    //check for fatal errors
    if (gpOutput::FatalNotice('include', $file)) {
        return false;
    }
    //set global variables
    foreach ($globals as $global) {
        global ${$global};
    }
    switch ($include_variation) {
        case 'include':
            $return = (include $file);
            break;
        case 'include_once':
            $return = (include_once $file);
            break;
        case 'require':
            $return = (require $file);
            break;
        case 'require_once':
            $return = (require_once $file);
            break;
    }
    gpOutput::PopCatchable();
    return $return;
}
Exemple #2
0
 /**
  * Execute a set of directives for theme areas, hooks and special pages
  *
  */
 static function ExecInfo($info, $args = array())
 {
     global $dataDir, $addonFolderName, $installed_addon, $config, $page, $gp_overwrite_scripts;
     //addonDir is deprecated as of 2.0b3
     if (isset($info['addonDir'])) {
         if (gp_safe_mode) {
             return;
         }
         gpPlugin::SetDataFolder($info['addonDir']);
     } elseif (isset($info['addon'])) {
         if (gp_safe_mode) {
             return;
         }
         gpPlugin::SetDataFolder($info['addon']);
     }
     //if addon was just installed
     if ($installed_addon && $installed_addon === $addonFolderName) {
         gpPlugin::ClearDataFolder();
         return $args;
     }
     // check for fatal errors
     if (self::FatalNotice('exec', $info)) {
         return $args;
     }
     //data
     if (!empty($info['data'])) {
         IncludeScript($dataDir . $info['data'], 'include_if', array('page', 'dataDir', 'langmessage'));
     }
     //script
     $has_script = false;
     if (isset($info['script'])) {
         if (is_array($gp_overwrite_scripts) && isset($gp_overwrite_scripts[$info['script']])) {
             $full_path = $gp_overwrite_scripts[$info['script']];
         } else {
             $full_path = $dataDir . $info['script'];
         }
         if (!file_exists($full_path)) {
             $name =& $config['addons'][$addonFolderName]['name'];
             trigger_error('gpEasy Error: Addon hook script doesn\'t exist. Script: ' . $info['script'] . ' Addon: ' . $name);
         } elseif (IncludeScript($full_path, 'include_once', array('page', 'dataDir', 'langmessage'))) {
             $has_script = true;
         }
     }
     //class & method
     if (!empty($info['class'])) {
         if (class_exists($info['class'])) {
             $object = new $info['class']($args);
             if (!empty($info['method'])) {
                 if (method_exists($object, $info['method'])) {
                     $args[0] = call_user_func_array(array($object, $info['method']), $args);
                 } elseif ($has_script) {
                     trigger_error('gpEasy Error: Addon hook method doesn\'t exist. Script: ' . $info['method']);
                 }
             }
         } elseif ($has_script) {
             $name =& $config['addons'][$addonFolderName]['name'];
             trigger_error('gpEasy Error: Addon class doesn\'t exist. Class: ' . $info['class'] . ' Addon: ' . $name);
         } else {
             trigger_error('gpEasy Error: Addon class doesn\'t exist. Class: ' . $info['class']);
         }
     } elseif (!empty($info['method'])) {
         $callback = $info['method'];
         //object callbacks since gpEasy 3.0
         if (is_string($callback) && strpos($callback, '->') !== false) {
             $has_script = true;
             list($object, $method) = explode('->', $callback);
             if (isset($GLOBALS[$object]) && is_object($GLOBALS[$object]) && method_exists($GLOBALS[$object], $method)) {
                 $callback = array($GLOBALS[$object], $method);
             }
         }
         if (is_callable($callback)) {
             $args[0] = call_user_func_array($callback, $args);
             $method_called = true;
         } elseif ($has_script) {
             $name =& $config['addons'][$addonFolderName]['name'];
             trigger_error('gpEasy Error: Addon hook method doesn\'t exist. Script: ' . $info['method'] . ' Addon: ' . $name);
         }
     }
     gpPlugin::ClearDataFolder();
     gpOutput::PopCatchable();
     return $args;
 }
Exemple #3
0
 /**
  * Execute a set of directives for theme areas, hooks and special pages
  *
  */
 static function ExecInfo($info, $args = array())
 {
     global $addonFolderName, $installed_addon;
     //addonDir is deprecated as of 2.0b3
     if (isset($info['addonDir'])) {
         if (gp_safe_mode) {
             return;
         }
         gpPlugin::SetDataFolder($info['addonDir']);
     } elseif (isset($info['addon'])) {
         if (gp_safe_mode) {
             return;
         }
         gpPlugin::SetDataFolder($info['addon']);
     }
     //if addon was just installed
     if ($installed_addon && $installed_addon === $addonFolderName) {
         gpPlugin::ClearDataFolder();
         return $args;
     }
     // check for fatal errors
     if (self::FatalNotice('exec', $info)) {
         return $args;
     }
     $args = self::_ExecInfo($info, $args);
     gpPlugin::ClearDataFolder();
     gpOutput::PopCatchable();
     return $args;
 }