Commit 2511b9e6 authored by mfer's avatar mfer
parent 3aa6cfa5
<?php
// $Id$
/* Installing bloginfo */
function bloginfo_install() {
......@@ -6,27 +7,30 @@ function bloginfo_install() {
case 'mysql':
case 'mysqli':
$ins = db_query('CREATE TABLE {bloginfo} ( '.
'uid varchar(10) NOT NULL, '.
'uid int(10) NOT NULL, '.
'title varchar(128) NOT NULL, '.
'description text NOT NULL, '.
"format int NOT NULL default '0',".
'PRIMARY KEY(uid) '.
') /*!40100 DEFAULT CHARACTER SET utf8 */');
break;
case 'pgsql':
$ins = db_query("CREATE TABLE {bloginfo} (
\"uid\" varchar(10) NOT NULL,
\"title\" varchar(128) NOT NULL,
\"description\" text NOT NULL,
UNIQUE (uid)
) ;
CREATE INDEX bloginfo_uid_idx ON {bloginfo} USING btree (uid);
");
uid int NOT NULL DEFAULT '0',
title varchar(128) NOT NULL DEFAULT '',
description text NOT NULL DEFAULT '',
format int NOT NULL default '0',
UNIQUE (uid)
) ;
CREATE INDEX bloginfo_uid_idx ON {bloginfo} (uid);
");
break;
}
if ($ins) {
drupal_set_message(t('Bloginfo module installed succesfully.'));
} else {
}
else {
drupal_set_message(t('Bloginfo module installation was unsuccesfull. The necessary database table may be created by hand. See the "README.txt" file in the "bloginfo/" modules directory for instructions.', 'error'));
}
return $ins;
......@@ -39,7 +43,7 @@ function bloginfo_uninstall() {
db_query('DROP TABLE {bloginfo}');
}
function bloginfo_update_1(){
function bloginfo_update_1() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
......@@ -52,4 +56,17 @@ function bloginfo_update_1(){
}
return $items;
}
?>
\ No newline at end of file
function bloginfo_update_2() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_change_column($items, 'bloginfo', 'uid', 'uid', 'int', array('not null' => TRUE));
break;
case 'mysql':
case 'mysqli':
$items[] = update_sql("ALTER TABLE {bloginfo} CHANGE uid uid INT( 10 ) NOT NULL");
break;
}
return $items;
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
function bloginfo_help($section) {
switch ($section) {
case 'admin/help#bloginfo':
$output = '<p>'. t('This module allows bloggers to have a title and description for their blog that is seperate from their username. This is similar to the title and descriptioin of blogs such as those at blogspot.com provided by blogger.'). '</p>';
$output = '<p>'. t('This module allows bloggers to have a title and description for their blog that is seperate from their username. This is similar to the title and descriptioin of blogs such as those at blogspot.com provided by blogger.') .'</p>';
$output .= '<p>'. t('The title and description is displayed in a block and is editable in a users \'my account\' options.') .'</p>';
return $output;
}
......@@ -24,7 +24,7 @@ function bloginfo_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'update':
case 'insert':
return bloginfo_save_bloginfo($edit, $user, $category);
return bloginfo_save_bloginfo($edit, $account, $category);
case 'form':
return bloginfo_form_bloginfo($edit, $account, $category);
case 'delete':
......@@ -36,30 +36,31 @@ function bloginfo_user($op, &$edit, &$account, $category = NULL) {
* Implementation of hook_block().
*/
function bloginfo_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Blog information');
return $blocks;
}
else if ($op == 'view') {
if (arg(0) == 'node' && is_numeric(arg(1))) $node = node_load(arg(1));
if (((arg(0) == 'blog' && is_numeric(arg(1))) || $node->type == 'blog')) {
if (arg(0) == 'blog') $authorid = arg(1);
else if ($node->type == 'blog') $authorid = $node->uid;
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $authorid);
if (mysql_num_rows($results) == 1){
$bloginfo = db_fetch_object($results);
$block['subject'] = check_plain($bloginfo->title);
$block['content'] = theme_bloginfo_block($bloginfo->description, $bloginfo->format);
return $block;
}
}
}
if ($op == 'list') {
$blocks[0]['info'] = t('Blog information');
return $blocks;
}
else if ($op == 'view') {
if (arg(0) == 'node' && is_numeric(arg(1))) $node = node_load(arg(1));
if (((arg(0) == 'blog' && is_numeric(arg(1))) || $node->type == 'blog')) {
if (arg(0) == 'blog') $authorid = arg(1);
else if ($node->type == 'blog') $authorid = $node->uid;
$count = db_result(db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $authorid));
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $authorid);
$bloginfo = db_fetch_object($results);
$block['subject'] = check_plain($bloginfo->title);
$block['content'] = theme('bloginfo_block', $bloginfo->description, $bloginfo->format, $authorid);
return $block;
}
}
}
}
/**
* Theme Function: Theme bloginfo block content
*/
function theme_bloginfo_block($description, $format) {
function theme_bloginfo_block($description, $format, $author) {
return check_markup($description, $format, FALSE);
}
......@@ -67,50 +68,50 @@ function theme_bloginfo_block($description, $format) {
* Helper function: create the form on the user settings page
*/
function bloginfo_form_bloginfo($edit, $account, $category) {
if ($category == 'account' && is_numeric(arg(1)) && (user_access('edit own bloginfo') || user_access('administer bloginfo'))) {
$result = db_query('SELECT title, description, format FROM {bloginfo} WHERE uid = %d', arg(1));
while ($bloginfo = db_fetch_object($result)) {
$mybloginfo['title'] = $bloginfo->title;
$mybloginfo['description'] = $bloginfo->description;
$mybloginfo['format'] = $bloginfo->format;
}
$fields['bloginfo_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Blog Information'),
'#weight' => 5);
$fields['bloginfo_settings']['Title'] = array(
'#type' => 'textfield',
'#title' => t('Blog Title'),
'#maxlength' => 128,
'#default_value' => $mybloginfo['title'],
'#description' => t('Your blog title will display on your blog and blog posts.'));
$fields['bloginfo_settings']['Description'] = array(
'#type' => 'textarea',
'#title' => t('Blog Description'),
'#default_value' => $mybloginfo['description'],
'#description' => t('Your blog description will display on your blog and blog posts.'));
$fields['bloginfo_settings']['desc_format'] = filter_form($mybloginfo['format']);
return $fields;
}//end if
if ($category == 'account' && is_numeric(arg(1)) && (user_access('edit own bloginfo') || user_access('administer bloginfo'))) {
$result = db_query('SELECT title, description, format FROM {bloginfo} WHERE uid = %d', arg(1));
while ($bloginfo = db_fetch_object($result)) {
$mybloginfo['title'] = $bloginfo->title;
$mybloginfo['description'] = $bloginfo->description;
$mybloginfo['format'] = $bloginfo->format;
}
$fields['bloginfo_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Blog Information'),
'#weight' => 5);
$fields['bloginfo_settings']['Title'] = array(
'#type' => 'textfield',
'#title' => t('Blog Title'),
'#maxlength' => 128,
'#default_value' => $mybloginfo['title'],
'#description' => t('Your blog title will display on your blog and blog posts.'));
$fields['bloginfo_settings']['Description'] = array(
'#type' => 'textarea',
'#title' => t('Blog Description'),
'#default_value' => $mybloginfo['description'],
'#description' => t('Your blog description will display on your blog and blog posts.'));
$fields['bloginfo_settings']['desc_format'] = filter_form($mybloginfo['format']);
return $fields;
}//end if
}//end function bloginfo_form_bloginfo()
/**
* Helper function: insert bloginfo into the database
*/
function bloginfo_save_bloginfo(&$edit, &$user, $category) {
if ($category == 'account') {
$results = db_query('SELECT uid FROM {bloginfo} WHERE uid = %d', arg(1));
//This is to update where info already exists in the database
if (db_num_rows($results) == 1){
db_query("Update {bloginfo} SET title = \"%s\", description = \"%s\", format = %d WHERE uid = %d", $edit['Title'], $edit['Description'], $edit['format'], arg(1));
}
//This adds it to the database for the first time
else {
db_query("INSERT INTO {bloginfo} (uid, title, description, format) VALUES (%d, \"%s\", \"%s\", %d)", arg(1), $edit['Title'], $edit['Description'], $edit['format']);
}
}
if ($category == 'account') {
if ( arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0 && arg(2) == 'edit') {
$results = db_query('SELECT uid FROM {bloginfo} WHERE uid = %d', arg(1));
//This is to update where info already exists in the database
if (db_num_rows($results) == 1) {
db_query("UPDATE {bloginfo} SET title = '%s', description = '%s', format = %d WHERE uid = %d", $edit['Title'], $edit['Description'], $edit['format'], arg(1));
}
//This adds it to the database for the first time
else {
db_query("INSERT INTO {bloginfo} (uid, title, description, format) VALUES (%d, '%s', '%s', %d)", arg(1), $edit['Title'], $edit['Description'], $edit['format']);
}
}
}
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment