Commit c5de70e1 authored by Joakim Schramm's avatar Joakim Schramm

Update HEAD to be in line with Core HEAD aka Drupal 7

parent 9ad52e6d
......@@ -2,4 +2,6 @@
name = Bloginfo
description = Blog title and description.
dependencies[] = blog
core = 6.x
core = 7.x
files[] = bloginfo.module
files[] = bloginfo.install
......@@ -19,22 +19,34 @@ function bloginfo_help($path, $arg) {
// hook_perm
function bloginfo_perm() {
return array('administer bloginfo', 'edit own bloginfo');
return array(
'administer bloginfo' => array(
'title' => t('Administer bloginfo'),
'description' => t('Determine if user can administer the blog information module'),
),
'edit own bloginfo' => array(
'title' => t('Edit own bloginfo'),
'description' => t('To set if user can edit own blog information'),
)
);
}
/**
* Implementation of hook_user().
*/
function bloginfo_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'update':
case 'insert':
function bloginfo_user_update(&$edit, &$account, $category = NULL) {
return bloginfo_save_bloginfo($edit, $account, $category);
case 'form':
}
function bloginfo_user_insert(&$edit, &$account, $category = NULL) {
return bloginfo_save_bloginfo($edit, $account, $category);
}
function bloginfo_user_form(&$edit, &$account, $category = NULL) {
return bloginfo_form_bloginfo($edit, $account, $category);
case 'delete':
db_query('DELETE FROM {bloginfo} WHERE uid = %d', $account->uid);
}
}
function bloginfo_user_delete(&$edit, &$account, $category = NULL) {
$num_deleted = db_delete('bloginfo')
->condition('uid', $account->uid)
->execute();
}
/**
......@@ -69,10 +81,10 @@ function bloginfo_block($op = 'list', $delta = 0, $edit = array()) {
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));
$count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = :uid", array(':uid' => $authorid,))->fetchField();
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $authorid);
$bloginfo = db_fetch_object($results);
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $authorid,));
$bloginfo = $results->fetch(PDO::FETCH_OBJ);
$block['subject'] = check_plain($bloginfo->title);
$block['content'] = theme('bloginfo_block', $bloginfo->description, $bloginfo->format, $authorid);
return $block;
......@@ -80,9 +92,9 @@ function bloginfo_block($op = 'list', $delta = 0, $edit = array()) {
}
break;
case 'blogroll':
$results = db_query("SELECT uid, title FROM {bloginfo} WHERE title <> '' ORDER BY title ASC");
while ($item = db_fetch_array($results)) {
$output[] = l($item['title'], 'blog/'. $item['uid']);
$results = db_query("SELECT uid, title FROM {bloginfo} WHERE title <> :title ORDER BY title ASC", array(':title' => '',));
foreach ($results as $item) {
$output[] = l($item->title, 'blog/'. $item->uid);
}
$block['subject'] = t('Blog Listing');
$block['content'] = theme('item_list', $output);
......@@ -98,10 +110,10 @@ function bloginfo_block($op = 'list', $delta = 0, $edit = array()) {
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));
$count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $node->uid)->fetchField();
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $node->uid);
$bloginfo = db_fetch_object($results);
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $node->uid,));
$bloginfo = $results->fetch(PDO::FETCH_OBJ);
$link['title'] = strlen($bloginfo->title) ? $bloginfo->title : $link['title'];
}
}
......@@ -131,8 +143,8 @@ function theme_bloginfo_block($description, $format, $author) {
*/
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)) {
$result = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => arg(1),));
foreach ($result as $bloginfo) {
$mybloginfo['title'] = $bloginfo->title;
$mybloginfo['description'] = $bloginfo->description;
$mybloginfo['format'] = $bloginfo->format;
......@@ -162,17 +174,28 @@ function bloginfo_form_bloginfo($edit, $account, $category) {
*/
function bloginfo_save_bloginfo(&$edit, &$user, $category) {
if ($category == 'account') {
//TODO: if (menu_get_object('user)...
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));
//??$results = db_query('SELECT uid FROM {bloginfo} WHERE uid = :uid', array(':uid' => arg(1),));
//This is to update where info already exists in the database
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));
if (db_query('SELECT COUNT(uid) FROM {bloginfo} WHERE uid = %d', arg(1))->fetchField() == 1) {
db_update('bloginfo')
->fields(array('title' => $edit['Title'], 'description' => $edit['Description'], 'format' => $edit['format'],))
->condition('uid', arg(1))
->execute();
}
//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']);
$id = db_insert('bloginfo')
->fields(array(
'uid' => arg(1),
'title' => $edit['Title'],
'description' => $edit['Description'],
'format' => $edit['format'],
))
->execute();
}
}
}
......@@ -184,10 +207,10 @@ function bloginfo_save_bloginfo(&$edit, &$user, $category) {
function bloginfo_page_user($account) {
$output = blog_page_user($account);
$count = db_result(db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $account->uid));
$count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,))->fetchField();
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $account->uid);
$bloginfo = db_fetch_object($results);
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,));
$bloginfo = $results->fetch(PDO::FETCH_OBJ);
if (strlen($bloginfo->title)) {
drupal_set_title($bloginfo->title);
......@@ -208,14 +231,14 @@ function bloginfo_feed_user($account) {
$channel['link'] = url('blog/'. $account->uid, array('absolute' => TRUE));
$items = array();
while ($row = db_fetch_object($result)) {
foreach ($result as $row) {
$items[] = $row->nid;
}
$count = db_result(db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = %d", $account->uid));
$count = db_query("SELECT COUNT(*) FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,))->fetchField();
if ($count == 1) {
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $account->uid);
$bloginfo = db_fetch_object($results);
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = :uid", array(':uid' => $account->uid,));
$bloginfo = $results->fetch(PDO::FETCH_OBJ);
$channel['title'] = strlen($bloginfo->title) ? $bloginfo->title : $channel['title'];
$channel['description'] = $bloginfo->description;
......
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