在Drupal中如何使用昵称代替用户名(账号)

黄超, 2009/12/20 18:57:34, § 0

原文名为:Create an alias instead of user username

This code was taken from the forum which I believe was also taken from somewhere else. I have made some fixes that allow it to work with comments and forums. Please claim responsibility if the original code was yours.

This snippet allows you to display user friendly alias names on posts and comments etc. This comes in useful if your using the Webserver_auth module and don’t want to see webserver usernames on your site. It allows the users to set an alias in their profile which is then displayed on the site. If the profile field isn’t set then it will use the users username.

You will need to enable the profile module and add a single line text field to your users profiles. You can call it anything you want but you will need to alter the code as appropriate. For this example I called my field ‘profile_fullname’.

In your template.php file you will need

<?php
function phptemplate_username($object) {
  if ($object->in_preview) {
      return theme_username($object);
  }
  return _phptemplate_callback('username', array('object' => $object));
}
?>

Create a file called ‘username.tpl.php’ with these contents

<?php
if ($object->uid && $object->name) {
// If the user has a full name defined, use that
$account = user_load(array(uid => $object->uid));
$profilename = $object->name;
  if (!empty($account->profile_fullname)) {
$profilename = $account->profile_fullname;
  }
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($profilename) > 20) {
$name = drupal_substr($profilename, 0, 15) .'...';
  }
  else {
$name = $profilename;
  }
  if (user_access('access user profiles')) {
$output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
  }
  else {
$output = check_plain($name);
  }
}
else if ($object->name) {
// Sometimes modules display content composed by people who are
  // not registered members of the site (e.g. mailing list or news
  // aggregator modules). This clause enables modules to display
  // the true author of the content.
if ($object->homepage) {
$output = l($object->name, $object->homepage, array('title' => t('View link')));
  }
  else {
$output = check_plain($object->name);
  }
$output .= ' ('. t('not verified') .')';
}
else {
$output = variable_get('anonymous', 'Anonymous');
}
print $output;
?>

You can change a page title with the drupal_set_title function.

A good place for it in this instance would be in a customized version of the theme_user_profile function, placed in your template.php file:

<?php
/**
* An implementation of theme_user_profile
*/
function phptemplate_user_profile($account, $fields) {
// change the profile page's title to the specified profile field
  // but only if we are actualy viewing a profile page and if the specified profile field has a value
if ((arg(0) == 'user') && $account->profile_fullname) {
drupal_set_title($account->profile_fullname);
  }
$output = '<div class="profile">';
$output .= theme('user_picture', $account);
  foreach ($fields as $category => $items) {
    if (strlen($category) > 0) {
$output .= '<h2 class="title">'. $category .'</h2>';
    }
$output .= '<dl>';
    foreach ($items as $item) {
      if (isset($item['title'])) {
$output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
      }
$output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
    }
$output .= '</dl>';
  }
$output .= '</div>';
  return $output;
}
?>

Next, to change the page title so that the user name is shown on the profile page, instead of the alias:

You can change a page title with the drupal_set_title function. A good place for it in this instance would be in a customized version of the theme_user_profile function, placed in your template.php file:

<?php
/**
* An implementation of theme_user_profile
*/
function phptemplate_user_profile($account, $fields) {
// change the profile page's title to the specified profile field
  // but only if we are actualy viewing a profile page and if the specified profile field has a value
if ((arg(0) == 'user') && $account->profile_fullname) {
drupal_set_title($account->profile_fullname);
  }
$output = '<div class="profile">';
$output .= theme('user_picture', $account);
  foreach ($fields as $category => $items) {
    if (strlen($category) > 0) {
$output .= '<h2 class="title">'. $category .'</h2>';
    }
$output .= '<dl>';
    foreach ($items as $item) {
      if (isset($item['title'])) {
$output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
      }
$output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
    }
$output .= '</dl>';
  }
$output .= '</div>';
  return $output;
}
?>

一代大师萨缪尔森去世

黄超, 2009/12/15 22:09:54, § 0

今天看到新闻,说美国经济学泰斗保罗•A•萨缪尔森十三日在其位于美国马萨诸塞州的家中逝世,享年九十四岁。

记得在大学上西方经济学时,还在图书馆借阅过他的《经济学》,感觉其遣词说理、图文举例皆深入浅出,比我们用的教材要好得多。

萨缪尔森在经济学领域中可以说是无处不在,被称为经济学界的最后一个通才。美联社当天在报道中总结萨缪尔森一生主要成就时说:他将数学分析方法引入经济学,帮助经济困境中上台的肯尼迪政府制定了著名的“肯尼迪减税方案”,并且写出了一部被数百万大学生奉为经典的教科书。

祝大师灵魂得升天堂!

人这一辈子

黄超, 2009/12/12 22:03:35, § 0

……

但聪慧如柔娘,理解他的意思并不费力,痴痴望着他的脸,幽幽道:“大人曾经对奴婢说,人这一辈子,最重要的是要搞清楚两个问题……”

“要的是什么,和正在做什么。”沈默点点头,轻声道:“只要在这两个问题上一直保持清醒,这一生就不会太令自己失望。”

……

语出三戒大师之《官居一品》

SNS的盈利模式

黄超, 2009/12/12 17:54:47, § 0

转自鲨鱼

2008年是SNS的快速发展的一年,一方面一些新的SNS类型网站得到了迅速的发展,一方面一些老的SNS网站继续积累着自己的用户,不断巩固自己的行业地位。但是巨头的SNS,还没有一家是赢利的,人们对SNS模式的赢利模式并不看好,甚至有些人认为SNS只是BBS模式的一个演变,属于光赚人气,不赚收入的活雷锋。但是从一些数据告诉我们,这样考虑有失偏颇。去年MySpace的在线广告营收8.2亿美元,这个数字无疑给中国的SNS网站以巨大的信心。那么SNS到底有哪些盈利模式呢,SNS爱好者鲨鱼考虑有下列五种方式。

传统的文字图片广告

这种广告是一些初始SNS网站的做法,因为SNS网站并没有多大的影响力,所以只能靠一些廉价的图片文字联盟广告来盈利。或者通过放置一些图片和文字链,搞一些让用户参与的活动。这种盈利模式和传统互联网网站没有多大区别,这里就不细谈了。

游戏联合运营的模式

这种模式校内最开始采用的,开始和千橡集团自己的猫游记还有另一款三国类的网页有些合作。51当时也和国内一家网页游戏合作。这种模式其实就是在廉价的出售流量,SNS并不缺少流量,但是缺乏影响力,所以得不到品牌广告商的青睐,所以只能靠这种方式出卖流量。

植入式的品牌广告

植入式的广告近些年得到了越来越多广告主的认可,一方面因为传统的广告太形式化,单调,点击率降低,效果开始越来越差。另一方面植入式广告可以巧妙的和网站的一些产品结合,让用户不知不觉的增加对该品牌的印象。其中开心网在停车位放置宝马的广告,还有在买房子中内置了万科房地产的广告。这些内置广告一般来说对用户并没有多大影响,用户一般对这种广告容易接受,反感成都很低。

APP应用分成的模式

越来越多的SNS网站推出了开放平台,提供一定量的API接口,允许其它公司开发的APP让自己网站的用户自由选择使用。这种形式,既可以满足取悦自己网站的用户,也能给开发者带来一定的金钱收益。自facebook从2007年8月份推出开房平台后,到现在大概吸引了超过40万的开发人员,APP程序超过了4万个,据说一款扑克类的游戏APP,去年在FACEBOOK上一年的收入在5000万美金。这个数据不知道真假,但是有个能肯定的数据是,slide.com公司去年年初再次融资5000万美金。slide公司是专门给myspace和facebook等做APP的公司。

虚拟增值服务

这种模式类似于腾讯的QQ秀,不过在SNS网站中采取这种的盈利模式,似乎并不能产生多少收入,用户已经买过QQ秀了,没有必要到各个SNS网站在分别买一套虚拟服装。目前这种模式51一直在做,但是效果比不理想。在一些专业行的SNS网站,还有一些类似向用户收费的增值服务,比如世纪佳缘,百合网等。收取一部分的费用成为高级别的会员,能享受更多的服务,比如可以查看一些用户照片等等。或者花费一定的虚拟货币,把自己征婚的照片放到首页,能让更多的用户了解自己。

免费撬动其它服务

以上几种都是能直接产生收入,还有一种情况是用户对这种服务仅仅是使用,死活不付费。但是这个用户可能是另一个服务的潜在收费用户,或者这个用户可以为另一个服务创造价值。比如有一款查杀木马的软件,注册费用大概几十元,如果不注册还享受正版服务的话,那就需要把指定的网址设为主页,通过那个主页来获得收入。再比如,注册天涯网站流程很负责,快捷的方式是通过手机注册,一次2块钱。还有就是邀请,还有一种就是先注册天涯邮箱,然后通过邮箱就可以激活天涯的账号。这个也属于通过撬动其它服务的模式,来最大化的发挥用户价值。这个是未来的发展方向之一,即使用户不付费,最大化的使用网站的其他服务,也是一种潜在的增值。

当然,SNS的盈利方式不止这几种,这六种只不过是现在比较常见的一些盈利方式。这些方式并不是单一的应用,一般都是几种模式混合起来一块使用。但是综合起来只有种,一是用户付费,二是广告商付费。只要不对用户产生负面影响,而且还能获得收入的,都是可商议的赢利模式。