Make WordPress Core

Changeset 223


Ignore:
Timestamp:
06/12/2003 10:48:52 PM (22 years ago)
Author:
mikelittle
Message:

More options functionaily
validation, error messages
More options

Location:
trunk/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/b2menutop.txt

    r150 r223  
    111   b2edit.php  Post / Edit
    223   b2team.php  Team
    3 4   b2options.php   Options
     34   wp-options.php  Options
    443   b2categories.php    Categories
    554   b2template.php  Template
  • trunk/wp-admin/optionhandler.php

    r209 r223  
    11<?php
    2 require_once('../b2config.php');
     2require_once('../wp-config.php');
    33/**
    44** get_option_widget()
     
    1313    $disabled = $editable ? '' : 'disabled';
    1414
    15     switch ($option_result->option_type)
    16     {
     15    switch ($option_result->option_type) {
    1716        case 1: // integer
    1817        case 3: // string
    19         case 6: // range -- treat same as integer for now!
    20         {
    21             if (($option_result->option_type == 1) || ($option_result->option_type == 1))
     18        case 6:  // range -- treat same as integer for now!
     19            if (($option_result->option_type == 1) || ($option_result->option_type == 1)) {
    2220                $width = 6;
    23             else
     21            } else {
    2422                $width = $option_result->option_width;
     23            }
    2524            return <<<TEXTINPUT
    2625                    <label for="$option_result->option_name">$option_result->option_name</label>$between
     
    2827TEXTINPUT;
    2928            //break;
    30         }
     29
    3130        case 2: // boolean
    32         {
    33             $true_selected = ($option_result->option_value == 'true') ? 'selected' : '';
    34             $false_selected = ($option_result->option_value == 'false') ? 'selected' : '';
     31            $true_selected = ($option_result->option_value == '1') ? 'selected' : '';
     32            $false_selected = ($option_result->option_value == '0') ? 'selected' : '';
    3533            return <<<BOOLSELECT
    3634                    <label for="$option_result->option_name">$option_result->option_name</label>$between
    3735                    <select name="$option_result->option_name" $disabled>
    38                     <option $true_selected>true</option>
    39                     <option $false_selected>false</option>
     36                    <option value="1" $true_selected>true</option>
     37                    <option value="0" $false_selected>false</option>
    4038                    </select>
    4139BOOLSELECT;
    4240            //break;
    43         }
     41           
    4442        case 5: // select
    45         {
    4643            $ret = <<<SELECT
    4744                    <label for="$option_result->option_name">$option_result->option_name</label>$between
     
    4946SELECT;
    5047
    51             $select = $wpdb->get_results("SELECT optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min "
     48            $select = $wpdb->get_results("SELECT optionvalue, optionvalue_desc "
    5249                                         ."FROM $tableoptionvalues "
    5350                                         ."WHERE option_id = $option_result->option_id "
    5451                                         ."ORDER BY optionvalue_seq");
    55             if ($select)
    56             {
    57                 foreach($select as $option)
    58                 {
     52            if ($select) {
     53                foreach($select as $option) {
    5954                    $ret .= '<option value="'.$option->optionvalue.'"';
    6055                    //error_log("comparing [$option_result->option_value] == [$option->optionvalue]");
    61                     if ($option_result->option_value == $option->optionvalue)
    62                     {
     56                    if ($option_result->option_value == $option->optionvalue) {
    6357                        $ret .=' selected';
    6458                    }
     
    6963            return $ret;
    7064            //break;
    71         }
     65       
     66        case 7: // SQL select
     67            // first get the sql to run
     68            $sql = $wpdb->get_var("SELECT optionvalue FROM $tableoptionvalues WHERE option_id = $option_result->option_id");
     69            if (!$sql) {
     70                return $option_result->option_name . $editable;
     71            }
     72
     73            // now we may need to do table name substitution
     74            eval("include('../wp-config.php');\$sql = \"$sql\";");
     75
     76            $ret = <<<SELECT
     77                    <label for="$option_result->option_name">$option_result->option_name</label>$between
     78                    <select name="$option_result->option_name" $disabled>
     79SELECT;
     80
     81            $select = $wpdb->get_results("$sql");
     82            if ($select) {
     83                foreach($select as $option) {
     84                    $ret .= '<option value="'.$option->value.'"';
     85                    //error_log("comparing [$option_result->option_value] == [$option->optionvalue]");
     86                    if ($option_result->option_value == $option->value) {
     87                        $ret .=' selected';
     88                    }
     89                    $ret .= ">$option->label</option>\n";
     90                }
     91            }
     92            $ret .= '</select>';
     93            return $ret;
     94            //break;
    7295
    7396    } // end switch
    7497    return $option_result->option_name . $editable;
    7598} // end function get_option_widget
     99
     100
     101function validate_option($option, $name, $val) {
     102    global $wpdb, $tableoptionvalues;
     103    $msg = '';
     104    switch ($option->option_type) {
     105        case 6: // range
     106            // get range
     107            $range = $wpdb->get_row("SELECT optionvalue_max, optionvalue_min FROM $tableoptionvalues WHERE option_id = $option->option_id");
     108            if ($range) {
     109                if (($val < $range->optionvalue_min) || ($val > $range->optionvalue_max)) {
     110                    $msg = "$name is outside the valid range ($range->optionvalue_min - $range->optionvalue_max). ";
     111                }
     112            }
     113    } // end switch
     114    return $msg;
     115} // end validate_option
     116   
    76117?>
  • trunk/wp-admin/temp-options-update.sql

    r208 r223  
    11--- temporary file to set up options data before update/install script is written.
    22
    3 -- will also need settings in b2config.php for these tables names
     3-- will also need settings in wp-config.php for these tables names
    44-- //new option tables
    55-- $tableoptions             = 'options';
     
    2222INSERT INTO optiontypes (optiontype_id, optiontype_name) VALUES (5, 'select');
    2323INSERT INTO optiontypes (optiontype_id, optiontype_name) VALUES (6, 'range');
     24INSERT INTO optiontypes (optiontype_id, optiontype_name) VALUES (7, 'sqlselect');
    2425
    2526
     
    3839--//base options from b2cofig
    3940INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(1,'siteurl', 3, 'http://mydomain.com', 'siteurl is your blog\'s URL: for example, \'http://mydomain.com/wordpress\' (no trailing slash !)', 8, 30);
    40 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(2,'blogfilename', 3, 'index.php', 'blogfilename is the name of the default file for your blog', 8);
    41 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(3,'blogname', 3, 'my weblog', 'blogname is the name of your blog', 8);
     41INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(2,'blogfilename', 3, 'index.php', 'blogfilename is the name of the default file for your blog', 8);
     42INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(3,'blogname', 3, 'my weblog', 'blogname is the name of your blog', 8);
    4243INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(4,'blogdescription', 3, 'babblings!', 'blogdescription is the description of your blog', 8, 40);
    43 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(5,'b2inc', 3, 'b2-include', 'This is the name of the include directory. No "/" allowed.', 8);
    44 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(6,'search_engine_friendly_urls', 2, 'false', 'Querystring Configuration ** (don\'t change if you don\'t know what you\'re doing)', 8);
    45 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(7,'new_users_can_blog', 2, 'false', 'whether you want new users to be able to post entries once they have registered', 8);
    46 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(8,'users_can_register', 2, 'true', 'whether you want to allow users to register on your blog', 8);
     44INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(6,'search_engine_friendly_urls', 2, 'false', 'Querystring Configuration ** (don\'t change if you don\'t know what you\'re doing)', 8);
     45INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(7,'new_users_can_blog', 2, '0', 'whether you want new users to be able to post entries once they have registered', 8);
     46INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(8,'users_can_register', 2, '1', 'whether you want to allow users to register on your blog', 8);
     47INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(54,'admin_email', 3, 'you@example.com', 'Your email (obvious eh?)', 8);
    4748
    4849--// general blog setup
    49 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(9 ,'start_of_week', 5, '1', 'day at the start of the week', 8);
    50 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(10,'use_preview', 2, 'true', 'Do you want to use the \'preview\' function', 8);
    51 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(11,'use_bbcode', 2, 'false', 'use BBCode, like [b]bold[/b]', 8);
    52 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(12,'use_gmcode', 2, 'false', 'use GreyMatter-styles: **bold** \\\\italic\\\\ __underline__', 8);
    53 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(13,'use_quicktags', 2, 'true', 'buttons for HTML tags (they won\'t work on IE Mac yet)', 8);
    54 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(14,'use_htmltrans', 2, 'true', 'IMPORTANT! set this to false if you are using Chinese, Japanese, Korean, or other double-bytes languages', 8);
    55 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(15,'use_balanceTags', 2, 'true', 'this could help balance your HTML code. if it gives bad results, set it to false', 8);
    56 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(16,'use_smilies', 2, 'true', 'set this to 1 to enable smiley conversion in posts (note: this makes smiley conversion in ALL posts)', 8);
     50INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(9 ,'start_of_week', 5, '1', 'day at the start of the week', 8);
     51INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(10,'use_preview', 2, '1', 'Do you want to use the \'preview\' function', 8);
     52INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(11,'use_bbcode', 2, '0', 'use BBCode, like [b]bold[/b]', 8);
     53INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(12,'use_gmcode', 2, '0', 'use GreyMatter-styles: **bold** \\\\italic\\\\ __underline__', 8);
     54INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(13,'use_quicktags', 2, '1', 'buttons for HTML tags (they won\'t work on IE Mac yet)', 8);
     55INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(14,'use_htmltrans', 2, '1', 'IMPORTANT! set this to false if you are using Chinese, Japanese, Korean, or other double-bytes languages', 8);
     56INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(15,'use_balanceTags', 2, '1', 'this could help balance your HTML code. if it gives bad results, set it to false', 8);
     57INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(16,'use_smilies', 2, '1', 'set this to 1 to enable smiley conversion in posts (note: this makes smiley conversion in ALL posts)', 8);
    5758INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(17,'smilies_directory', 3, 'http://mydomain.com/b2-img/smilies', 'the directory where your smilies are (no trailing slash)', 8, 40);
    58 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(18,'require_name_email', 2, 'false', 'set this to true to require e-mail and name, or false to allow comments without e-mail/name', 8);
     59INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(18,'require_name_email', 2, '0', 'set this to true to require e-mail and name, or false to allow comments without e-mail/name', 8);
    5960INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(19,'comment_allowed_tags', 3, '<b><i><strong><em><code><blockquote><p><br><strike><a>', 'here is a list of the tags that are allowed in the comments. You can add tags to the list, just add them in the string, add only the opening tag: for example, only \'&lt;a>\' instead of \'&lt;a href="">&lt;/a>\'', 8, 40);
    60 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(20,'comments_notify', 2, 'true', 'set this to true to let every author be notified about comments on their posts', 8);
     61INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(20,'comments_notify', 2, '1', 'set this to true to let every author be notified about comments on their posts', 8);
    6162
    6263--//rss/rdf feeds
    63 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(21,'posts_per_rss', 1, '10', 'number of last posts to syndicate', 8);
    64 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(22,'rss_language', 3, 'en', 'the language of your blog ( see this: http://backend.userland.com/stories/storyReader$16 )', 8);
    65 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(23,'rss_encoded_html', 2, 'false', 'for b2rss.php: allow encoded HTML in &lt;description> tag?', 8);
    66 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(24,'rss_excerpt_length', 1, '50', 'length (in words) of excerpts in the RSS feed? 0=unlimited note: in b2rss.php, this will be set to 0 if you use encoded HTML', 8);
    67 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(25,'rss_use_excerpt', 2, 'true', 'use the excerpt field for rss feed.', 8);
    68 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(26,'use_weblogsping', 2, 'false', 'set this to true if you want your site to be listed on http://weblogs.com when you add a new post', 8);
    69 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(27,'use_blodotgsping', 2, 'false', 'set this to true if you want your site to be listed on http://blo.gs when you add a new post', 8);
     64INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(21,'posts_per_rss', 1, '10', 'number of last posts to syndicate', 8);
     65INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(22,'rss_language', 3, 'en', 'the language of your blog ( see this: http://backend.userland.com/stories/storyReader$16 )', 8);
     66INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(23,'rss_encoded_html', 2, '0', 'for b2rss.php: allow encoded HTML in &lt;description> tag?', 8);
     67INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(24,'rss_excerpt_length', 1, '50', 'length (in words) of excerpts in the RSS feed? 0=unlimited note: in b2rss.php, this will be set to 0 if you use encoded HTML', 8);
     68INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(25,'rss_use_excerpt', 2, '1', 'use the excerpt field for rss feed.', 8);
     69INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(26,'use_weblogsping', 2, '0', 'set this to true if you want your site to be listed on http://weblogs.com when you add a new post', 8);
     70INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(27,'use_blodotgsping', 2, '0', 'set this to true if you want your site to be listed on http://blo.gs when you add a new post', 8);
    7071INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(28,'blodotgsping_url', 3, 'http://mydomain.com', 'You shouldn\'t need to change this.', 8, 30);
    71 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(29,'use_trackback', 2, 'true', 'set this to 0 or 1, whether you want to allow your posts to be trackback\'able or not note: setting it to zero would also disable sending trackbacks', 8);
    72 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(30,'use_pingback', 2, 'true', 'set this to 0 or 1, whether you want to allow your posts to be pingback\'able or not note: setting it to zero would also disable sending pingbacks', 8);
     72INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(29,'use_trackback', 2, '1', 'set this to 0 or 1, whether you want to allow your posts to be trackback\'able or not note: setting it to zero would also disable sending trackbacks', 8);
     73INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(30,'use_pingback', 2, '1', 'set this to 0 or 1, whether you want to allow your posts to be pingback\'able or not note: setting it to zero would also disable sending pingbacks', 8);
    7374
    7475--//file upload
    75 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(31,'use_fileupload', 2, 'false', 'set this to false to disable file upload, or true to enable it', 8);
     76INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(31,'use_fileupload', 2, '0', 'set this to false to disable file upload, or true to enable it', 8);
    7677INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(32,'fileupload_realpath', 3, '/home/your/site/wordpress/images', 'enter the real path of the directory where you\'ll upload the pictures \nif you\'re unsure about what your real path is, please ask your host\'s support staff \nnote that the  directory must be writable by the webserver (chmod 766) \nnote for windows-servers users: use forwardslashes instead of backslashes', 8, 40);
    7778INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(33,'fileupload_url', 3, 'http://mydomain.com/images', 'enter the URL of that directory (it\'s used to generate the links to the uploded files)', 8, 40);
    78 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(34,'fileupload_allowedtypes', 3, ' jpg gif png ', 'accepted file types, you can add to that list if you want. note: add a space before and after each file type. example: \' jpg gif png \'', 8);
    79 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(35,'fileupload_maxk', 1, '96', 'by default, most servers limit the size of uploads to 2048 KB, if you want to set it to a lower value, here it is (you cannot set a higher value than your server limit)', 8);
    80 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(36,'fileupload_minlevel', 1, '1', 'you may not want all users to upload pictures/files, so you can set a minimum level for this', 8);
     79INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(34,'fileupload_allowedtypes', 3, ' jpg gif png ', 'accepted file types, you can add to that list if you want. note: add a space before and after each file type. example: \' jpg gif png \'', 8);
     80INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(35,'fileupload_maxk', 1, '96', 'by default, most servers limit the size of uploads to 2048 KB, if you want to set it to a lower value, here it is (you cannot set a higher value than your server limit)', 8);
     81INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level)               VALUES(36,'fileupload_minlevel', 1, '1', 'you may not want all users to upload pictures/files, so you can set a minimum level for this', 8);
    8182INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(37,'fileupload_allowedusers', 3, '', '...or you may authorize only some users. enter their logins here, separated by spaces if you leave that variable blank, all users who have the minimum level are authorized to upload note: add a space before and after each login name example: \' barbara anne \'', 8, 30);
    8283
     
    8990INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(43,'subjectprefix', 3, 'blog:', 'subject prefix', 8);
    9091INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(44,'bodyterminator', 3, '___', 'body terminator string (starting from this string, everything will be ignored, including this string)', 8);
    91 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(45,'emailtestonly', 2, 'false', 'set this to true to run in test mode', 8);
    92 INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(46,'use_phoneemail', 2, 'false', 'some mobile phone email services will send identical subject & content on the same line if you use such a service, set use_phoneemail to true, and indicate a separator string', 8);
     92INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(45,'emailtestonly', 2, '0', 'set this to true to run in test mode', 8);
     93INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(46,'use_phoneemail', 2, '0', 'some mobile phone email services will send identical subject & content on the same line if you use such a service, set use_phoneemail to true, and indicate a separator string', 8);
    9394INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(47,'phoneemail_separator', 3, ':::', 'when you compose your message, you\'ll type your subject then the separator string then you type your login:password, then the separator, then content', 8);
    9495
     
    178179INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,3,3);
    179180INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,4,4);
    180 INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,5,5);
    181 INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,6,6);
    182 INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,7,7);
    183 INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,8,8);
     181INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,6,5);
     182INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,7,6);
     183INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,8,7);
     184INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(6,54,8);
    184185
    185186
    186187CREATE TABLE optionvalues (
    187188  option_id int(11) NOT NULL,
    188   optionvalue varchar(64),
     189  optionvalue tinytext(64),
    189190  optionvalue_desc varchar(255),
    190191  optionvalue_max int(11),
     
    194195  INDEX (option_id, optionvalue_seq)
    195196) TYPE=MyISAM;
     197
    196198
    197199-- select data for what to show
     
    211213INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '6', 'Saturday', null,null,3);
    212214
     215
     216--// Add in a new page for POST DEFAULTS
     217
     218--// default_post_status  select one of publish draft private
     219--// default_comment_status select one of open closed
     220--// default_ping_status select one of open closed
     221--// default_pingback_flag select one of checked unchecked
     222--// default_post_category sql_select "SELECT cat_id AS value, cat_name AS label FROM $tablecategories order by cat_name"
     223
     224INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(55,'default_post_status',    5, 'publish', 'The default state of each new post', 8);
     225INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(56,'default_comment_status', 5, 'open', 'The default state of comments for each new post', 8);
     226INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(57,'default_ping_status',    5, 'open', 'The default ping state for each new post', 8);
     227INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(58,'default_pingback_flag',  5, '1', 'Whether the \'PingBack the URLs in this post\' checkbox should be checked by default', 8);
     228INSERT INTO options (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES(59,'default_post_category',  7, '1', 'The default category for each new post', 8);
     229
     230INSERT INTO optiongroups (group_id,  group_name, group_desc) VALUES(7, 'Default post options', 'Default settings for new posts.');
     231INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(7,55,1 );
     232INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(7,56,2 );
     233INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(7,57,3 );
     234INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(7,58,4 );
     235INSERT INTO optiongroup_options (group_id, option_id, seq) VALUES(7,59,5 );
     236
     237-- select data for post_status
     238INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'publish', 'Publish', null,null,1);
     239INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'draft',   'Draft',   null,null,2);
     240INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'private', 'Private', null,null,3);
     241
     242-- select data for comment_status
     243INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (56, 'open', 'Open',   null,null,1);
     244INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (56, 'closed', 'Closed', null,null,2);
     245
     246-- select data for ping_status (aargh duplication!)
     247INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (57, 'open', 'Open',   null,null,1);
     248INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (57, 'closed', 'Closed', null,null,2);
     249
     250-- select data for pingback flag
     251INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (58, '1', 'Checked',   null,null,1);
     252INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (58, '0', 'Unchecked', null,null,2);
     253
     254-- sql select data for default
     255INSERT INTO optionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (59, 'SELECT cat_id AS value, cat_name AS label FROM $tablecategories order by cat_name', '', null,null,1);
  • trunk/wp-admin/wp-options.php

    r208 r223  
    1212    }
    1313    return $array;
    14 } 
     14}
    1515
    1616if (!get_magic_quotes_gpc()) {
     
    4040    $option_group_id = 1;
    4141}
     42
    4243switch($action) {
    4344
     
    4546    $standalone = 1;
    4647    include("./b2header.php");
    47     //do something
    48     $message = "Settings saved...";
    49     //error_log("got action=update and option_group_id=$option_group_id");
    50 
     48    $any_changed = 0;
     49   
    5150    // iterate through the list of options in this group
    5251    // pull the vars from the post
     
    5857                                  . "WHERE group_id = $option_group_id "
    5958                                  . "ORDER BY seq");
    60     if ($options)
    61     {
    62         foreach ($options as $option)
    63         {
    64             $this_name = $option->option_name;
    65             $old_val = stripslashes($option->option_value);
    66             $new_val = $HTTP_POST_VARS[$this_name];
    67             // get type and validate
     59    if ($options) {
     60        foreach ($options as $option) {
     61            // should we even bother checking?
     62            if ($user_level >= $option->option_admin_level) {
     63                $this_name = $option->option_name;
     64                $old_val = stripslashes($option->option_value);
     65                $new_val = $HTTP_POST_VARS[$this_name];
    6866
    69             //error_log("update checking $this_name: $old_val and $new_val");
    70             if ($new_val != $old_val)
    71             {
    72                 //error_log("updating $this_name from $old_val to $new_val");
    73                 $result = $wpdb->query("UPDATE $tableoptions SET option_value='".addslashes($new_val)."' WHERE option_id=$option->option_id");
    74                 if (!$result)
    75                 {
    76                     $message .= "Error while saving $this_name. ";
     67                if ($new_val != $old_val) {
     68                    // get type and validate
     69                    $msg = validate_option($option, $this_name, $new_val);
     70                    if ($msg == '') {
     71                        //no error message
     72                        $result = $wpdb->query("UPDATE $tableoptions SET option_value = '" . addslashes($new_val) . "' WHERE option_id = $option->option_id");
     73                        if (!$result) {
     74                            $db_errors .= " SQL error while saving $this_name. ";
     75                        } else {
     76                            ++$any_changed;
     77                        }
     78                    } else {
     79                        $validation_message .= $msg;
     80                    }
    7781                }
    7882            }
    7983        } // end foreach
     84        unset($cache_settings); // so they will be re-read
     85        get_settings('siteurl'); // make it happen now
     86    } // end if options
     87   
     88    if ($any_changed) {
     89        $message = $any_changed . ' setting(s) saved... ';
    8090    }
    81     //header("Location: $this_file?option_group_id=$option_group_id");
    82     //break;
    83     //fall through
     91   
     92    if (($dB_errors != '') || ($validation_message != '')) {
     93        if ($message != '') {
     94            $message .= '<br />and ';
     95        }
     96        $message .= $dB_errors . '<br />' . $validation_message;
     97    }
     98       
     99    //break; //fall through
    84100
    85101default:
    86     $standalone=0;
     102    $standalone = 0;
    87103    include ("./b2header.php");
    88104    if ($user_level <= 3) {
     
    94110    //we need to iterate through the available option groups.
    95111    $option_groups = $wpdb->get_results("SELECT group_id, group_name, group_desc, group_longdesc FROM $tableoptiongroups ORDER BY group_id");
    96     foreach ($option_groups as $option_group)
    97     {
    98         if ($option_group->group_id == $option_group_id)
    99         {
     112    foreach ($option_groups as $option_group) {
     113        if ($option_group->group_id == $option_group_id) {
    100114            $current_desc=$option_group->group_desc;
    101115            $current_long_desc = $option_group->group_longdesc;
    102116            echo("  <li id=\"current2\"><a href=\"$this_file?option_group_id={$option_group->group_id}\" title=\"{$option_group->group_desc}\">{$option_group->group_name}</a></li>\n");
    103         }
    104         else
    105         {
     117        } else {
    106118            echo("  <li><a href=\"$this_file?option_group_id={$option_group->group_id}\" title=\"{$option_group->group_desc}\">{$option_group->group_name}</a></li>\n");
    107119        }
     
    115127    <input type="hidden" name="action" value="update" />
    116128    <input type="hidden" name="option_group_id" value="<?php echo $option_group_id; ?>" />
    117            
     129
    118130  <table width="90%" cellpadding="2" cellspacing="2" border="0">
    119131<?php
     
    124136                                  . "WHERE group_id = $option_group_id "
    125137                                  . "ORDER BY seq");
    126     if ($options)
    127     {
    128         foreach ($options as $option)
    129         {
     138    if ($options) {
     139        foreach ($options as $option) {
    130140            echo('<tr><td width="10%" valign="top">'. get_option_widget($option, ($user_level >= $option->option_admin_level), '</td><td width="15%" valign="top" style="border: 1px solid #ccc">'));
    131141            echo("</td><td  valign='top' class='helptext'>$option->option_description</td></tr>\n");
Note: See TracChangeset for help on using the changeset viewer.