Commit 17602d96 authored by mfer's avatar mfer

The bloginfo module adds a blog title and description to your blogs. It is a...

The bloginfo module adds a blog title and description to your blogs.  It is a simple module that adds 2 additional fields to the users account screen, for those who have permission, to have a blog title and blog description.  These are then put into a block that can be placed like any other block.  The title is the block title and the description is the block content.
parents
-----------------------------------------------------------
bloginfo.module for Drupal
by Matt Farina
contact: http://drupal.org/user/25701/contact
-----------------------------------------------------------
The bloginfo module adds a blog title and description to your blogs. It is a simple module that adds 2 additional fields to the users account screen, for those who have permission, to have a blog title and blog description. These are then put into a block that can be placed like any other block. The title is the block title and the description is the block content.
The idea is to have a blog title and description like one via blogger.com.
The block will only display on a users blog list or blog post who have filled in the settings.
INSTALL
-------
1) Place the folder bloginfo into your drupal modules directory.
2) Go to admin/modules and activate the bloginfo module
3) Go to admin/access and set the access privileges to use this module.
\ No newline at end of file
<?php
/* Installing bloginfo */
function bloginfo_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ins = db_query('CREATE TABLE {bloginfo} ( '.
'uid varchar(10) NOT NULL, '.
'title varchar(128) NOT NULL, '.
'description text NOT NULL, '.
'PRIMARY KEY(uid) '.
') /*!40100 DEFAULT CHARACTER SET utf8 */');
break;
}
if ($ins) {
drupal_set_message(t('Bloginfo module installed succesfully.'));
} 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;
}
?>
\ No newline at end of file
<?php
// $Id$
// hook_help
function bloginfo_help($section) {
switch ($section) {
case 'admin/modules#description':
// This description is shown in the listing at admin/modules.
return t('Blog title and description.');
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('The title and description is displayed in a block and is editable in a users \'my account\' options.') .'</p>';
return $output;
}
}
// hook_perm
function bloginfo_perm() {
return array('administer bloginfo', 'edit own bloginfo');
}
/**
* Implementation of hook_user().
*/
function bloginfo_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'update':
case 'insert':
return bloginfo_save_bloginfo($edit, $user, $category);
case 'form':
return bloginfo_form_bloginfo($edit, $account, $category);
case 'delete':
db_query('DELETE FROM {bloginfo} WHERE uid = %d', $user->uid);
}
}
/**
* 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 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'] = check_plain($bloginfo->description);
return $block;
}
}
}
}
/**
* 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(db_rewrite_sql('SELECT b.title, b.description FROM {bloginfo} b WHERE b.uid = %d', 'b'), arg(1));
while ($bloginfo = db_fetch_object($result)) {
$mybloginfo['title'] = $bloginfo->title;
$mybloginfo['description'] = $bloginfo->description;
}
$fields['bloginfo_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Blog Information'),
'#collapsible' => TRUE,
'#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.'));
return $fields;
}//end if
}//end function bloginfo_form_bloginfo()
/**
* Helper function: insert bloginfo into the database
*/
function bloginfo_save_bloginfo(&$edit, &$user) {
$results = db_query(db_rewrite_sql('SELECT b.uid FROM {bloginfo} b WHERE b.uid = %d', 'b'), arg(1));
//This is to update where info already exists in the database
if (mysql_num_rows($results) == 1){
db_query("Update {bloginfo} SET title = \"%s\", description = \"%s\" WHERE uid = %d", $edit['Title'], $edit['Description'], arg(1));
}
//This adds it to the database for the first time
else {
db_query("INSERT INTO {bloginfo} (uid, title, description) VALUES (%d, \"%s\", \"%s\")", arg(1), $edit['Title'], $edit['Description']);
}
}
?>
\ No newline at end of file
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