九/080
tMessage修改一处错误
今天在后台看到一些朋友的留言,猛然发现用户名都是terrysco。。。看来是取用户名的时候写错了,修改如下:
<?php
function theme_tmessage_admin_form($form) {
drupal_add_css(drupal_get_path(’module’, ‘tmessage’) . ‘/tmessage.css’);
$output = ”;
$messages = tmessage_get_message();
if ($messages) {
foreach ($messages as $message) {
$output .= ‘<hr class="break_line" />’;
$output .= ‘<div class="tmessage">’;
$output .= ‘<div class="tmessage_body">’;
$output .= drupal_render($form['mid'][$message->mid]);
$output .= ‘<strong>’ .check_plain($message->name). ‘</strong>’;
$output .= check_plain($message->content);
$output .= ‘</div>’;
$output .= ‘<div class="tmessage_author_info">’;
// here.
if ($message->uid) {
$from = user_load(array(’uid’ => $message->uid));
$username = check_plain($from->name);
}
else {
$username = variable_get(’anonymous’, t(’no name’));
}
// ends.
$output .= ‘<span class="tmessage_name_link">’ .$username. ‘ [' .check_plain($message->contact). ']</span>’;
$output .= ‘<span class="tmessage_addr">’ .format_date($message->last, ‘custom’, ‘Y-m-d H:i’). ‘ [' .$message->hostname. ']</span>’;
$output .= ‘</div></div>’;
}
$output .= ‘<div class="tmessage_op">’ .drupal_render($form). ‘</div>’;
$output .= theme(’pager’);
}
return $output;
}
?>
七/080
原创drupal留言本tMessage
没有找到一个简单实用的留言本系统,就在自己写一个。:-)
简单功能如下:
在tmessage路径有留言的表单可以发表;
权限管理分为是否允许留言和管理留言;
管理留言目前就一个删除功能,可批量删除。
可在后台自定义设置留言时间间隔;
可以对留言进行分类,比如“问题反馈”,“好的建议”;
用户可留下联系方式,以方便问题解决;
留言分类在后台可管理;
tmessage.info文件
; $Id: tmessage.info,v 1.1.2.1 2008/09/04 23:06:42 terrysco Exp $
name = tMessage
description = Allows users to leave a message.
package = terrysco
tmessage.install文件
<?php // $Id: /** * Implementation of hook_install(). */ function tmessage_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': // add favorite terms managment by terrysco 20080620. db_query("CREATE TABLE {tmessage} ( mid INT NOT NULL AUTO_INCREMENT, uid INT NOT NULL, content text, hostname varchar(255), last INT, PRIMARY KEY (mid) ) Type=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */; "); break; case 'pgsql': // TODO: need someone to do this on PostgreSQL break; } } /** * Implementation of hook_uninstall(). */ function tmessage_uninstall() { db_query('DROP TABLE {tmessage}'); } ?>
module文件:
<?php // $Id$ /* * Implementation of hook_perm. */ function tmessage_perm() { return array('leave a message', 'administer message'); } /* * Implementation of hook_menu. */ function tmessage_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/settings/tmessage', 'title' => t('Message Management'), 'callback' => 'drupal_get_form', 'callback arguments' => array('tmessage_admin_form'), 'access' => user_access('administer message'), ); $items[] = array( 'path' => 'admin/settings/tmessage/list', 'type' => MENU_DEFAULT_LOCAL_TASK, 'title' => t('Message List'), 'weight' => 0, 'access' => user_access('administer message'), ); $items[] = array( 'path' => 'admin/settings/tmessage/config', 'title' => t('Message Config'), 'type' => MENU_LOCAL_TASK, 'callback' => 'tmessage_config_page', 'access' => user_access('administer message'), 'weight' => 1, ); $items[] = array( 'path' => 'tmessage', 'title' => t('Message'), 'callback' => 'drupal_get_form', 'callback arguments' => array('tmessage_add_form'), 'type' => MENU_CALLBACK, 'access' => user_access('leave a message'), ); $items[] = array( 'path' => 'tmessage/type/edit', 'title' => t('Edit Message'), 'callback' => 'drupal_get_form', 'callback arguments' => array('tmessage_type_edit_form'), 'type' => MENU_CALLBACK, 'access' => user_access('administer message'), ); $items[] = array( 'path' => 'tmessage/type/delete', 'callback' => 'tmessage_type_delete', 'type' => MENU_CALLBACK, 'access' => user_access('administer message'), ); } return $items; } function tmessage_get_type() { $rows = array(); $rows[0] = t('select the message type...'); $result = db_query('SELECT * FROM {tmessage_type}'); while ($type = db_fetch_object($result)) { $rows[$type->tid] = $type->name; } return $rows; } function tmessage_config_form() { $form = array(); $form['tmessage_post_interval_min'] = array( '#type' => 'textfield', '#title' => t('post interval'), '#description' => t('setup the time between 2 posts'), '#required' => TRUE, '#default_value' => variable_get('tmessage_post_interval_min', 60), '#size' => 10, ); return system_settings_form($form); } function tmessage_add_type_form() { $form = array(); $form['typename'] = array( '#type' => 'textfield', '#required' => TRUE, '#size' => 30, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('create type'), ); return $form; } function tmessage_add_type_form_submit($form_id, $form_values) { $typename = $form_values['typename']; db_query("INSERT INTO {tmessage_type} SET name = '%s'", $typename); drupal_set_message(t('you have created a message type.')); } function tmessage_config_page() { $output .= drupal_get_form('tmessage_config_form'); $output .= '<br /><div class="container-inline">'; $output .= drupal_get_form('tmessage_add_type_form'); $output .= '</div>'; $result = db_query('SELECT * FROM {tmessage_type}'); while ($type = db_fetch_object($result)) { $rows[] = array( check_plain($type->name), l(t('edit'), "tmessage/type/edit/$type->tid"). ' ' .l(t('delete'), "tmessage/type/delete/$type->tid", array('onclick' => 'return confirm("'. t('confirm to delete this type?'). '");')) ); } $header = array(t('typename'), t('operation')); $output .= theme('table', $header, $rows); return $output; } /* * generate a form to add message. */ function tmessage_add_form() { global $user; $form = array(); $form['desc'] = array( '#type' => 'markup', '#value' => t('hi @username. welcome to give us advice, any words you leave will improve our service', array('@username' => $user->name)), ); $form['typeid'] = array( '#type' => 'select', '#title' => t('Message type'), '#required' => TRUE, '#options' => tmessage_get_type(), ); $form['content'] = array( '#type' => 'textarea', '#title' => t('Message'), '#rows' => 5, '#cols' => 50, '#resizable' => TRUE, '#required' => TRUE, ); $form['contact'] = array( '#type' => 'textfield', '#size' => 30, '#title' => t('contact'), '#description' => t('email or phone number here.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('submit'), ); return $form; } /* * validate the submit time, if less than 60 sec, throw an error. */ function tmessage_add_form_validate($form_id, $form_values) { global $user; $last_post = db_result(db_query("SELECT MAX(last) AS last_post FROM {tmessage} WHERE hostname = '%s'", $user->hostname)); $post_interval = variable_get('tmessage_post_interval_min', 60); if ($form_values['typeid'] == 0) { form_set_error('typeid', t('you must select the feedback type.')); } if ((time() - $last_post) < $post_interval) { form_set_error('content', t('you must leave a message after 1 min.')); } } /* * handle the form tmessage_form. */ function tmessage_add_form_submit($form_id, $form_values) { global $user; $typeid = intval($form_values['typeid']); $content = $form_values['content']; db_query("INSERT INTO {tmessage} SET uid = %d, tid = %d, content = '%s', hostname = '%s', contact = '%s', last = %d", $user->uid, $typeid, $content, $user->hostname, $form_values['contact'], time()); drupal_set_message(t('you send a message successfully!')); } /* * return an array of all message. */ function tmessage_get_message() { $rows = array(); $result = db_query('SELECT * FROM {tmessage} t INNER JOIN {tmessage_type} s USING(tid) ORDER BY last DESC'); while ($message = db_fetch_object($result)) { $rows[$message->mid] = $message; } return $rows; } function tmessage_admin_form() { $form = array(); $form['#tree'] = TRUE; foreach (tmessage_get_message() as $message) { $form['mid'][$message->mid] = array( '#type' => 'checkbox', '#return_value' => $message->mid, ); } $form['delete'] = array( '#type' => 'submit', '#value' => t('delete'), '#attributes' => array( 'onclick'=> 'return confirm("' . t('confirm to delete the message selected?') . '")' ), ); return $form; } function tmessage_delete_item($mid) { if ($mid) { db_query('DELETE FROM {tmessage} WHERE mid = %d', intval($mid)); } } function tmessage_admin_form_submit($form_id, $form_values) { $messages = array_filter($form_values['mid']); foreach ($messages as $mid) { tmessage_delete_item($mid); } drupal_set_message(t('you have successfully delete the message selected.')); } function theme_tmessage_admin_form($form) { drupal_add_css(drupal_get_path('module', 'tmessage') . '/tmessage.css'); $output = ''; $messages = tmessage_get_message(); if ($messages) { foreach ($messages as $message) { $output .= '<hr class="break_line" />'; $output .= '<div class="tmessage">'; $output .= '<div class="tmessage_body">'; $output .= drupal_render($form['mid'][$message->mid]); $output .= '<strong>' .check_plain($message->name). '</strong>'; $output .= check_plain($message->content); $output .= '</div>'; $output .= '<div class="tmessage_author_info">'; if ($message->uid) { $from = user_load(array('uid' => $message->uid)); $username = check_plain($from->name); } else { $username = variable_get('anonymous', t('no name')); } $output .= '<span class="tmessage_name_link">' .$username. ' [' .check_plain($message->contact). ']</span>'; $output .= '<span class="tmessage_addr">' .format_date($message->last, 'custom', 'Y-m-d H:i'). ' [' .$message->hostname. ']</span>'; $output .= '</div></div>'; } $output .= '<div class="tmessage_op">' .drupal_render($form). '</div>'; $output .= theme('pager'); } return $output; } function tmessage_type_edit_form($tid) { $tid = intval($tid); $typename = db_result(db_query('SELECT name FROM {tmessage_type} WHERE tid = %d', $tid)); $form = array(); if ($typename) { $form['typeid'] = array( '#type' => 'value', '#value' => $tid, ); $form['typename'] = array( '#type' => 'textfield', '#title' => t('edit the type name'), '#default_value' => $typename, '#size' => 10, '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('submit'), ); } return $form; } function tmessage_type_edit_form_submit($form_id, $form_values) { db_query("UPDATE {tmessage_type} SET name = '%s' WHERE tid = %d", $form_values['typename'], $form_values['typeid']); drupal_set_message('the message type has been updated!'); return 'admin/settings/tmessage/config'; } function tmessage_type_delete($tid) { $tid = intval($tid); db_query('DELETE FROM {tmessage_type} WHERE tid = %d', $tid); db_query('DELETE FROM {tmessage} WHERE tid = %d', $tid); drupal_set_message('the message type has been deleted!'); drupal_goto('admin/settings/tmessage/config'); }
分类目录
- CMS/FrameWork (41)
- Javascript/jQuery/AS (1)
- Linux/Shell/DB (35)
- Mobile (1)
- PHP/Python/Perl/Ruby (10)
- The Bible 2 Me (5)
- Web Architecture (5)
- Web Security (7)
- 互联网改变生活 (6)
随机文章
标签
最近评论
- 懂得 在 drupal views教程 上的评论
- tw 在 关于我 上的评论
- dfgdfg 在 php和python的比较 上的评论
- 竞价联盟 在 《高性能网站建设进阶指南》书评 上的评论
- anyLiv 在 Google的pac-man 上的评论