Commit 9ad52e6d authored by Joakim Schramm's avatar Joakim Schramm

Bring HEAD up in parity with D6, adding code contributed in #225981 by...

Bring HEAD up in parity with D6, adding code contributed in #225981 by gdevlugt, jng12 and I simply made minor adjustments.
parent 747ee867
; $Id$
name = Bloginfo
description = Blog title and description.
dependencies = blog
\ No newline at end of file
dependencies[] = blog
core = 6.x
<?php
// $Id$
/**
* @file
* The Blog title and description module.
*
*/
/* Installing bloginfo */
function bloginfo_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ins = db_query('CREATE TABLE {bloginfo} ( '.
'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 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) {
$result = drupal_install_schema('bloginfo');
if ($result[0]['success'] == 1) {
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;
}
/**
* Implementation of hook_schema().
*/
function bloginfo_schema() {
$schema['bloginfo'] = array(
'description' => t('This holds the bloginfo data.'),
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'description' => array(
'type' => 'text',
'not null' => TRUE,
),
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('uid'),
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
function bloginfo_uninstall() {
db_query('DROP TABLE {bloginfo}');
drupal_uninstall_schema('bloginfo');
}
function bloginfo_update_1() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
db_add_column($items, 'bloginfo', 'format', 'int', array('not null' => TRUE, 'default' => 0));
break;
case 'mysql':
case 'mysqli':
$items[] = update_sql("ALTER TABLE {bloginfo} ADD COLUMN format int NOT NULL default '0'");
break;
}
return $items;
$ret = array();
db_add_field($ret, 'bloginfo', 'format', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
return $ret;
}
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;
$ret = array();
db_change_field($ret, 'bloginfo', 'uid', 'uid', array('type' => 'int', 'not null' => TRUE));
return $ret;
}
\ No newline at end of file
<?php
// $Id$
/**
* @file
* The Blog title and description module.
*
*/
// hook_help
function bloginfo_help($section) {
switch ($section) {
function bloginfo_help($path, $arg) {
switch ($path) {
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>';
......@@ -32,19 +37,35 @@ function bloginfo_user($op, &$edit, &$account, $category = NULL) {
}
}
/**
* Implementation of hook_menu_alter().
*/
function bloginfo_menu_alter(&$callbacks) {
// Use wrapper function instead of blog_page_user() so the page title
// can be set.
$callbacks['blog/%user_current']['page callback'] = 'bloginfo_page_user';
// Use wrapper function instead of blog_feed_user() so the feed title
// can be set.
$callbacks['blog/%user/feed']['page callback'] = 'bloginfo_feed_user';
}
/**
* Implementation of hook_block().
*/
function bloginfo_block($op = 'list', $delta = 0) {
function bloginfo_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks['bloginfo']['info'] = t('Blog information');
$blocks['blogroll']['info'] = t('Blogroll by blog title');
$blocks['bloginfo'] = array(
'info' => t('Blog information'),
);
$blocks['blogroll'] = array(
'info' => t('Blogroll by blog title'),
);
return $blocks;
}
else if ($op == 'view') {
switch($delta) {
case 'bloginfo':
if (arg(0) == 'node' && is_numeric(arg(1))) $node = node_load(arg(1));
if ($node = menu_get_object());
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;
......@@ -54,7 +75,7 @@ function bloginfo_block($op = 'list', $delta = 0) {
$bloginfo = db_fetch_object($results);
$block['subject'] = check_plain($bloginfo->title);
$block['content'] = theme('bloginfo_block', $bloginfo->description, $bloginfo->format, $authorid);
return $block;
return $block;
}
}
break;
......@@ -67,10 +88,37 @@ function bloginfo_block($op = 'list', $delta = 0) {
$block['content'] = theme('item_list', $output);
return $block;
break;
}
}
}
}
/**
* Implementation of hook_link_alter().
*/
function bloginfo_link_alter(&$links, $node) {
foreach ($links AS $module => &$link) {
if ($module == 'blog_usernames_blog') {
$count = db_result(db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $node->uid));
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $node->uid);
$bloginfo = db_fetch_object($results);
$link['title'] = strlen($bloginfo->title) ? $bloginfo->title : $link['title'];
}
}
}
}
/**
* Implementation of hook_theme()
*/
function bloginfo_theme() {
return array(
'bloginfo_block' => array(
'arguments' => array('description', 'format', 'author'),
),
);
}
/**
* Theme Function: Theme bloginfo block content
*/
......@@ -116,12 +164,12 @@ function bloginfo_save_bloginfo(&$edit, &$user, $category) {
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));
if (db_result(db_query('SELECT COUNT(uid) FROM {bloginfo} WHERE uid = %d', arg(1))) == 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']);
......@@ -129,3 +177,49 @@ function bloginfo_save_bloginfo(&$edit, &$user, $category) {
}
}
}
/**
* Wrapper for blog_page_user(). Sets the page title if available.
*/
function bloginfo_page_user($account) {
$output = blog_page_user($account);
$count = db_result(db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $account->uid));
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $account->uid);
$bloginfo = db_fetch_object($results);
if (strlen($bloginfo->title)) {
drupal_set_title($bloginfo->title);
}
}
return $output;
}
/**
* Menu callback; displays an RSS feed containing recent blog entries of all users.
*
* Customization of blog_feed_user().
*/
function bloginfo_feed_user($account) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $account->uid, 0, variable_get('feed_default_items', 10));
$channel['title'] = $account->name ."'s blog";
$channel['link'] = url('blog/'. $account->uid, array('absolute' => TRUE));
$items = array();
while ($row = db_fetch_object($result)) {
$items[] = $row->nid;
}
$count = db_result(db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $account->uid));
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $account->uid);
$bloginfo = db_fetch_object($results);
$channel['title'] = strlen($bloginfo->title) ? $bloginfo->title : $channel['title'];
$channel['description'] = $bloginfo->description;
}
node_feed($items, $channel);
}
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