/**
  * Retrieve a list of available plugin classes
  *
  * This function searches through all directories and loaded internal files and tries
  * to detect the serendipity plugins.
  *
  * @access public
  * @param   boolean     If true, only event plugins will be searched. If false, sidebar plugins will be searched.
  * @return
  */
 function &enum_plugin_classes($event_only = false)
 {
     global $serendipity;
     $classes = array();
     /* built-in classes first */
     $cls = get_declared_classes();
     foreach ($cls as $class_name) {
         if (strncmp($class_name, 'serendipity_', 6)) {
             continue;
         }
         $p = get_parent_class($class_name);
         while ($p != 'serendipity_plugin' && $p != 'serendipity_event' && $p !== false) {
             $p = get_parent_class($p);
         }
         if ($p == 'serendipity_plugin' && $class_name != 'serendipity_event' && (!$event_only || is_null($event_only))) {
             $classes[$class_name] = array('name' => '@' . $class_name, 'type' => 'internal_event', 'true_name' => $class_name, 'pluginPath' => '');
         } elseif ($p == 'serendipity_event' && $class_name != 'serendipity_event' && ($event_only || is_null($event_only))) {
             $classes[$class_name] = array('name' => '@' . $class_name, 'type' => 'internal_plugin', 'true_name' => $class_name, 'pluginPath' => '');
         }
     }
     /* GLOBAL third-party classes next */
     $ppath = serendipity_getRealDir(__FILE__) . 'plugins';
     serendipity_plugin_api::traverse_plugin_dir($ppath, $classes, $event_only);
     /* LOCAL third-party classes next */
     $local_ppath = $serendipity['serendipityPath'] . 'plugins';
     if ($ppath != $local_ppath) {
         serendipity_plugin_api::traverse_plugin_dir($local_ppath, $classes, $event_only);
     }
     return $classes;
 }
/**
 * Check a default value of a config item from the configuration template files
 *
 * @access public
 * @param   string      Name of the config item to check
 * @param   string      The default value, if none is found
 * @param   boolean     If true, it's the personal config template, if false its the global config template
 * @param   string      Protected fields will not be echo'd in the HTML form
 * @return  string      The default value
 */
function serendipity_query_default($optname, $default, $usertemplate = false, $type = 'string')
{
    global $serendipity;
    /* I won't tell you the password, it's MD5 anyway, you can't do anything with it */
    if ($type == 'protected' && IS_installed === true) {
        return '';
    }
    switch ($optname) {
        case 'permalinkStructure':
            return $default;
        case 'dbType':
            if (extension_loaded('mysqli')) {
                $type = 'mysqli';
            }
            if (extension_loaded('PDO') && in_array('pgsql', PDO::getAvailableDrivers())) {
                $type = 'pdo-postgres';
            }
            if (extension_loaded('pgsql')) {
                $type = 'postgres';
            }
            if (extension_loaded('mysql')) {
                $type = 'mysql';
            }
            return $type;
        case 'serendipityPath':
            if (empty($_SERVER['PHP_SELF'])) {
                $test_path1 = $_SERVER['DOCUMENT_ROOT'] . rtrim(dirname($_SERVER['SCRIPT_FILENAME']), '/') . '/';
            } else {
                $test_path1 = $_SERVER['DOCUMENT_ROOT'] . rtrim(dirname($_SERVER['PHP_SELF']), '/') . '/';
            }
            $test_path2 = serendipity_getRealDir(__FILE__);
            if (file_exists($test_path1 . 'serendipity_admin.php')) {
                return $test_path1;
            } elseif (defined('S9Y_DATA_PATH')) {
                // Shared installation!
                return S9Y_DATA_PATH;
            } else {
                return $test_path2;
            }
        case 'serendipityHTTPPath':
            return rtrim(dirname($_SERVER['PHP_SELF']), '/') . '/';
        case 'baseURL':
            $ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on';
            $port = $_SERVER['SERVER_PORT'];
            return sprintf('http%s://%s%s%s', $ssl ? 's' : '', preg_replace('@^([^:]+):?.*$@', '\\1', $_SERVER['HTTP_HOST']), $ssl && $port != 443 || !$ssl && $port != 80 ? ':' . $port : '', rtrim(dirname($_SERVER['PHP_SELF']), '/') . '/');
        case 'convert':
            $path = array();
            $path[] = ini_get('safe_mode_exec_dir');
            if (isset($_SERVER['PATH'])) {
                $path = array_merge($path, explode(PATH_SEPARATOR, $_SERVER['PATH']));
            }
            /* add some other possible locations to the path while we are at it,
             * as these are not always included in the apache path */
            $path[] = '/usr/X11R6/bin';
            $path[] = '/usr/bin';
            $path[] = '/usr/local/bin';
            foreach ($path as $dir) {
                if (!empty($dir) && (function_exists('is_executable') && @is_readable($dir) && @is_executable($dir . '/convert')) || @is_file($dir . '/convert')) {
                    return $dir . '/convert';
                }
                if (!empty($dir) && (function_exists('is_executable') && @is_readable($dir . '/convert') && @is_executable($dir . '/convert.exe')) || @is_file($dir . '/convert.exe')) {
                    return $dir . '/convert.exe';
                }
            }
            return $default;
        case 'rewrite':
            return serendipity_check_rewrite($default);
        default:
            if ($usertemplate) {
                return serendipity_get_user_var($optname, $serendipity['authorid'], $default);
            }
            return $default;
    }
}