 |
boardom b2 message board
|
View previous topic :: View next topic |
Author |
Message |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Wed Nov 20, 2002 1:21 am Post subject: B2 Extra Options |
|
|
Hi people,
I've just released a new hack. Inspired by a conversation on IM about the recent request to be able to turn off a blog from the admin tool. I have produced a hack which will allow you to define arbitrary extra options, set their values in the admin tool and use them in your templates.
This will give you the ability to, for example, add the following to your main template:
[php:1:5029d4e098]<?php
include_once("./b2extraoptions.php");
if (get_extraoption('blog_closed') == 'true') {
die("The blog is closed, sorry.");
?>[/php:1:5029d4e098]
and be able to control the value of 'blog_closed' from the admin tool.
Or you could define a option called 'default_skin' and again administer that from the admin. The sky is the limit
This is a 0.1 release, but I think it is already useful.
You can find details, and down load it from http://zed1.com/b2extraoptions/b2extraoptions.html
Please post bug reports, fixes, comments, questions, etc. to this topic in this forum.
Enjoy,
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Wed Nov 20, 2002 2:46 am Post subject: |
|
|
It looks like there may be a problem with using this in IE 6.
Probably Javascript. I'll look into it tomorrow.
Sorry,
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Wed Nov 20, 2002 3:01 am Post subject: |
|
|
It was broken on IE5 too. So this fix for IE5 may fix it for IE 6
Update: It does indeed fix it for IE 6
At line 375 in b2extraoptionsmanager.php change to
Code: |
// is the user allowed to change the value?
if ($row->option_level <= $user_level) {
echo(" <td><input type=\"submit\" name=\"change\" onclick=\"forms[0].option_id.value='$row->option_id'; forms[0].action.value='changevalue'; \" value=\"Change\" class=\"search\" /></td>\n");
}
// is the user allowed to edit the option?
if (get_extraoption_level('add_options_min_level') <= $user_level) {
echo(" <td><input type=\"submit\" name=\"edit\" onclick=\"forms[0].option_id.value='$row->option_id'; forms[0].action.value='editoption'; \" value=\"Edit\" class=\"search\" /></td>\n");
}
|
I'll so another release tomorrow.
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
seeya
Joined: 13 Jul 2002 Posts: 32 Location: Singapore
|
Posted: Wed Nov 27, 2002 6:08 pm Post subject: |
|
|
wat do u mean by this ???
Quote: | Execute the SQL from the file b2extraoptions.sql. This will create the two tables and add two extra options. |
|
|
Back to top |
|
 |
.Chris
Joined: 30 Apr 2002 Posts: 186 Location: Hawaii
|
Posted: Wed Nov 27, 2002 7:21 pm Post subject: |
|
|
I thought I'd try it out but I can't even get it installed. I keep getting this error: Code: | You have an error in your SQL syntax near '\'\',
option_type int(11) NOT NULL default 1,
option_value varchar(255) NO' at line 3
|
Or it says the quary was empty.. |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Thu Nov 28, 2002 12:02 am Post subject: |
|
|
I will turn the table creation into a php script.
I've been pretty much asked the same thing for another of my hacks.
I'll work on it now.... _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Thu Nov 28, 2002 1:42 am Post subject: |
|
|
OK. Here is a first pass at a table creation script. Upload this to your B2 directory as b2extraoptions.install.php and 'call' it with your browser http://www.your.domain/b2extraoptions.install.php
[php:1:61f3fca75c]<?php
// $Id$
//
// B2 Extra Options
// Copyright (C) 2002 Mike Little -- [email protected]
//
// This is an add-on to b2 weblog / news publishing tool
// b2 is copyright (c)2001, 2002 by Michel Valdrighi - [email protected]
//
// **********************************************************************
// Copyright (C) 2002 Mike Little
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// Mike Little ([email protected])
// *****************************************************************
// Start Connect To MYSQL
require_once("b2config.php");
include_once("$b2inc/b2vars.php");
include_once("$b2inc/b2functions.php");
$tableextraoptions = "b2extraoptions";
$tableextraoptiontypes = "b2optiontypes";
$got_options = false;
$got_types = false;
?><html>
<head>
<title>b2 > Installation</title>
</head>
<body>
<p>Checking for tables...</p>
<?php
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
if ($row[0] == $tableextraoptions)
$got_options = true;
if ($row[0] == $tableextraoptiontypes)
$got_types = true;
//print "Table: $row[0]<br />\n";
}
if (!$got_types) {
echo "<p>Can't find table '$tableextraoptiontypes', gonna create it...</p>\n";
$sql = "CREATE TABLE $tableextraoptiontypes ( " .
" option_id int(11) NOT NULL auto_increment, " .
" option_name tinytext NOT NULL, ".
" PRIMARY KEY (option_id) ".
") ";
$result = mysql_query($sql) or print ("Can't create the table '$tableextraoptiontypes' in the database.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Table '$tableextraoptiontypes' created OK</p>\n";
$got_types = true;
}
} else {
echo "<p>Found table '$tableextraoptiontypes', don't need to create it...</p>\n";
}
if (!$got_options) {
echo "<p>Can't find '$tableextraoptions', gonna create it...</p>\n";
$sql = "CREATE TABLE $tableextraoptions ( " .
" option_id int(11) NOT NULL auto_increment, " .
" option_name varchar(64) UNIQUE NOT NULL default '', " .
" option_type int(11) NOT NULL default 1, " .
" option_value varchar(255) NOT NULL default '', " .
" option_description varchar(255) NOT NULL default '', " .
" option_level int NOT NULL DEFAULT '1', " .
" PRIMARY KEY (option_id) " .
") ";
$result = mysql_query($sql) or print ("Can't create the table '$tableextraoptions' in the database.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Table '$tableextraoptions' created OK</p>\n";
$got_options = true;
}
} else {
echo "<p>Found table '$tableextraoptions', don't need to create it...</p>\n";
}
if ($got_options && $got_types) {
$got_1 = false;
$got_2 = false;
$got_3 = false;
$got_4 = false;
echo "<p>Looking for types...</p>\n";
$sql = "SELECT option_id, option_name FROM $tableextraoptiontypes ";
$result = mysql_query($sql) or print ("Can't query '$tableextraoptiontypes'.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
while ($row = mysql_fetch_object($result)) {
if ($row->{'option_id'} == 1) {
echo "<p>You have got type 1. Good!</p>\n";
$got_1 = true;
}
if ($row->{'option_id'} == 2) {
echo "<p>You have got type 2. Good!</p>\n";
$got_2 = true;
}
if ($row->{'option_id'} == 3) {
echo "<p>You have got type 3. Good!</p>\n";
$got_3 = true;
}
if ($row->{'option_id'} == 4) {
echo "<p>You have got type 4. Good!</p>\n";
$got_4 = true;
}
}
if (!$got_1) {
echo "<p>Gonna insert type 1...</p>\n";
$sql = "INSERT INTO $tableextraoptiontypes (option_id, option_name) VALUES (1, 'int')";
$result = mysql_query($sql) or print ("Can't insert type.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted type Ok</p>\n";
$got_1 = true;
}
}
if (!$got_2) {
echo "<p>Gonna insert type 2...</p>\n";
$sql = "INSERT INTO $tableextraoptiontypes (option_id, option_name) VALUES (2, 'boolean')";
$result = mysql_query($sql) or print ("Can't insert type.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted type Ok</p>\n";
$got_2 = true;
}
}
if (!$got_3) {
echo "<p>Gonna insert type 3...</p>\n";
$sql = "INSERT INTO $tableextraoptiontypes (option_id, option_name) VALUES (3, 'string')";
$result = mysql_query($sql) or print ("Can't insert type.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted type Ok</p>\n";
$got_3 = true;
}
}
if (!$got_4) {
echo "<p>Gonna insert type 4...</p>\n";
$sql = "INSERT INTO $tableextraoptiontypes (option_id, option_name) VALUES (4, 'date')";
$result = mysql_query($sql) or print ("Can't insert type.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted type Ok</p>\n";
$got_4 = true;
}
}
} else {
echo ("No results from query '$tableextraoptiontypes'.<br />" . $sql . "<br />" . mysql_error());
}
$got_option_1 = false;
$got_option_2 = false;
echo "<p>Looking for extra options...</p>\n";
$sql = "SELECT option_name FROM $tableextraoptions ";
$result = mysql_query($sql) or print ("Can't query '$tableextraoptions'.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
while ($row = mysql_fetch_object($result)) {
if ($row->{'option_name'} == 'add_options_min_level') {
echo "<p>You have got 'add_options_min_level'. Good!</p>\n";
$got_option_1 = true;
}
if ($row->{'option_name'} == 'blog_closed') {
echo "<p>You have got 'blog_closed'. Good!</p>\n";
$got_option_2 = true;
}
}
if (!$got_option_1) {
echo "<p>Gonna insert extra option 1...</p>\n";
$sql = "INSERT INTO $tableextraoptions " .
" (option_id, option_name, option_type, option_value, option_description, option_level) " .
" VALUES (1,'add_options_min_level', 1, '10','The minimum user level to add/edit extra options.', 10)";
$result = mysql_query($sql) or print ("Can't query extra option.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted extra option Ok</p>\n";
$got_option_1 = true;
}
}
if (!$got_option_2) {
echo "<p>Gonna insert extra option 2...</p>\n";
$sql = "INSERT INTO $tableextraoptions " .
" (option_id, option_name, option_type, option_value, option_description, option_level) " .
" VALUES (2,'blog_closed', 2, 'false','Set this to true to temporarily close the blog.', 5)";
$result = mysql_query($sql) or print ("Can't query extra option.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted extra option Ok</p>\n";
$got_option_2 = true;
}
}
}
}
if ($got_1 && $got_2 && $got_3 && $got_4 && $got_option_1 && $got_option_2) {
echo "<p>All done.</p>\n";
}
?>
</body>
</html>
[/php:1:61f3fca75c]
Let me know of any problems. I'll include this in the next release.
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Fri Nov 29, 2002 12:44 am Post subject: New version |
|
|
Folks,
There is a new version of B2 Extra Options. Version 0.2
The only new things in this version are a fix for the JavaScript problems in Internet Explorer
and the addition of the install file (posted earlier)
You can download it from the B2 Options page
Enjoy,
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
name_me
Joined: 31 Jan 2003 Posts: 12 Location: Ukraine
|
Posted: Sun Feb 02, 2003 11:32 am Post subject: |
|
|
mikelittle wrote: | Because the error message says "(Using password: NO)" it sounds like you don't have your b2config.php set up correctly, or the file is not in the same directory as b2config.php
Make sure you have your database password set up in b2config.php and that all theb2extraoptions files are in your main b2 directory.
|
Hello, mikelittle!
No, b2config is ok and in a valid place - my blog works correctly. Besides, today, i have installed your hack B2 Link Manager using it php installer and all was ok. So the problem is not in my config. Any suggestions? |
|
Back to top |
|
 |
name_me
Joined: 31 Jan 2003 Posts: 12 Location: Ukraine
|
Posted: Sun Feb 02, 2003 11:46 am Post subject: |
|
|
Greetings again
mikelittle, i've compared installers from b2LinkManager and b2ExtraOptions and noticed that in b2extraoptions.install.php you've forgotten to insert this lines (i got them from b2links.install.php):
[list=]$connexion = mysql_connect($server,$loginsql,$passsql) or die("Can't connect to the database<br>".mysql_error());
$dbconnexion = mysql_select_db($base, $connexion);[/list]
After that, all code of installer worked correctly. |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Sun Feb 02, 2003 3:09 pm Post subject: |
|
|
Hi name_me,
Glad you got it sorted. I'll have to get round to issuing a new version with the fix in. Meanwhile, I'll add something to the web page.
Thanks for working it out.
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
xytx
Joined: 24 May 2003 Posts: 48
|
Posted: Fri May 30, 2003 6:18 am Post subject: |
|
|
i did everything but i dont have a tab on my after login page? did i do something wrong? |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Fri May 30, 2003 7:03 am Post subject: |
|
|
Is your account admin level 5 or above? _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
xytx
Joined: 24 May 2003 Posts: 48
|
Posted: Fri May 30, 2003 7:08 am Post subject: |
|
|
yea its 10. |
|
Back to top |
|
 |
mikelittle
Joined: 11 May 2002 Posts: 376 Location: UK
|
Posted: Sat May 31, 2003 10:59 am Post subject: |
|
|
Sorry for the delay in replying,
When you say you "did everything" did you make sure to use real tab characters, not spaces on the line added to b2menutop.txt
Also just a check, but could it have wrapped over to the left of the page?
Mike _________________ Mike Little
http://zed1.com/journalized/
"Share what you know. Learn what you don't." |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2 © 2001, 2002 phpBB Group
|