Location: PHPKode > projects > Geeklog Plugins, Static Pages and Blocks > multifaq/install_defaults.php
<?php

/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | MultiFAQ plugin                                                          |
// +---------------------------------------------------------------------------+
// | install_defaults.php                                                      |
// |                                                                           |
// | Initial Installation Defaults used when loading the online configuration  |
// | records. These settings are only used during the initial installation     |
// | and not referenced any more once the plugin is installed.                 |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2009 by the following authors:                              |
// |                                                                           |
// | Author:  http://lior.weissbrod.com                                               |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program is free software; you can redistribute it and/or             |
// | modify it under the terms of the GNU General Public License               |
// | as published by the Free Software Foundation; either version 2            |
// | of the License, or (at your option) any later version.                    |
// |                                                                           |
// | This program is distributed in the hope that it will be useful,           |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
// | GNU General Public License for more details.                              |
// |                                                                           |
// | You should have received a copy of the GNU General Public License         |
// | along with this program; if not, write to the Free Software Foundation,   |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
// |                                                                           |
// +---------------------------------------------------------------------------+
//
// $Id: install_defaults.php

if (strpos($_SERVER['PHP_SELF'], 'install_defaults.php') !== false) {
    die('This file can not be used on its own!');
}

/*
 * Default settings
 *
 * Initial Installation Defaults used when loading the online configuration
 * records. These settings are only used during the initial installation
 * and not referenced any more once the plugin is installed
 *
 */

$_MULTIFAQ_DEFAULT["require_login"]   = false;   // Require login

$_MULTIFAQ_DEFAULT["default_commentcode"]   = -1;   // -1=no comments, 0=allowed, 1=closed

$_MULTIFAQ_DEFAULT["global_delete"]   = true;   // delete questions with their topics?

$_MULTIFAQ_DEFAULT["show_recent"]   = true;   // show recent aditions or not?
$_MULTIFAQ_DEFAULT["recent_count"]  = 10;   // how many recent aditions?
$_MULTIFAQ_DEFAULT["show_top_x"]    = true; // show top x hits or not?
$_MULTIFAQ_DEFAULT["top_x_count"]   = 10;   // how many top x hits?
// this number is also valid for the statistics !

$_MULTIFAQ_DEFAULT['replace_homepage'] = false;
// use the multifaq CSS only on the user/admin pages of the plugin
// setting this to false will disable eventually
// added CSS for the whatsnew-block etc.
$_MULTIFAQ_DEFAULT['dynamic_css']   = true;

$_MULTIFAQ_DEFAULT["javascript"] = true; // Show the answers right in the menu
$_MULTIFAQ_DEFAULT["javascript_search_open_count"] = 5; // Maximum open answers
$_MULTIFAQ_DEFAULT["expand_all"]        = true;   // Show always all topics and Q&A
$_MULTIFAQ_DEFAULT["tree_edit_links"]        = true;   // Show edit links even in trees
$_MULTIFAQ_DEFAULT["new_at_end"]        = false;   // Put new questions below old questions
$_MULTIFAQ_DEFAULT["show_datetime"]     = true;   // Show date & time of last edition of Q&A
$_MULTIFAQ_DEFAULT["new_faq_interval"]  = 1209600; // = 14 days (86400= 1 day in seconds)
$_MULTIFAQ_DEFAULT["hide_whatsnew"]     = false; // true or false
$_MULTIFAQ_DEFAULT['count_admin'] = false; // count hits from (logged in) admins?
$_MULTIFAQ_DEFAULT['count_editor'] = false; // count hits from (logged in) translators?
$_MULTIFAQ_DEFAULT['default_permissions'] = array(3, 2, 2, 2);

/**
* Initialize plugin configuration
*
* Creates the database entries for the configuation if they don't already
* exist. Initial values can be taken from the old config.php
*
* @return   boolean     true: success; false: an error occurred
*
*/
function plugin_initconfig_multifaq($_MULTIFAQ_DEFAULT)
{
    global $_PLG_MULTIFAQ, $_TABLES;

    $value_is_number = array("_count", "_interval");
    $value_is_multiple_choice = array("default_commentcode" => 5 );
    $c = config::get_instance();

    if ($c->group_exists($_PLG_MULTIFAQ['pi_name']))
        DB_query ("DELETE FROM {$_TABLES['conf_values']} WHERE group_name = '{$_PLG_MULTIFAQ['pi_name']}'");

    if (!isset($_POST['reset']) && is_array($_PLG_MULTIFAQ) && (count($_PLG_MULTIFAQ) > 1))
        foreach ($_MULTIFAQ_DEFAULT as $key => $value)
               if (array_key_exists($key, $_PLG_MULTIFAQ) && $value <> $_PLG_MULTIFAQ[$key])
                      $_MULTIFAQ_DEFAULT[$key] = $_PLG_MULTIFAQ[$key];

        $c->add('sg_main', NULL, 'subgroup', 0, 0, NULL, 0, true, $_PLG_MULTIFAQ['pi_name']);
        $c->add('fs_main', NULL, 'fieldset', 0, 0, NULL, 0, true, $_PLG_MULTIFAQ['pi_name']);

        $i = 0;
        foreach ($_MULTIFAQ_DEFAULT as $key => $value) {
                $i += 1;
                if ($key <> 'default_permissions') {
                          $group = 0;
                          $type = 'select';
                          foreach ($value_is_number as $value2)
                                 if (strpos($key, $value2) !== false) {
                                      $type = 'text';
                                      break;
                                 }
                          if ($type == 'select' && is_numeric($value)) {
                                 if (array_key_exists($key, $value_is_multiple_choice))
                                      $group = $value_is_multiple_choice[$key];
                                 else {
                                      if ($value == 0)
                                            $value = false;
                                      elseif ($value == 1)
                                            $value = true;
                                 }
                          }
                          $c->add($key, $value, $type, 0, 0, $group, $i*10, true, $_PLG_MULTIFAQ['pi_name']);
                }
        }

        $c->add('fs_permissions', NULL, 'fieldset', 0, 1, NULL, 0, true, $_PLG_MULTIFAQ['pi_name']);
        $c->add('default_permissions', $_MULTIFAQ_DEFAULT['default_permissions'],
                '@select', 0, 1, 12, $i*10, true, $_PLG_MULTIFAQ['pi_name']);

    return true;
}

?>
Return current item: Geeklog Plugins, Static Pages and Blocks