十二 24 2010

Drupal二次开发之如何发送邮件附件

Category: Drupallixiphp @ 2010-12-24 15:57:48

默认drupal_mail()函数不包含附件的功能。互联网搜索,很多人建议使用mimemail module,但没有提供以它如何能够从你的代码中使用的建议。

Mime Mail模块image 这是Mime Mail模块安装截图。

如何使用MIME Mail

下面是英文参数说明:

+/**
+ * Sends a mime-encoded e-mail.
+ *
+ * This function first determines the mail engine to use, then prepares the
+ * message by calling the mail engine's prepare function, or
+ * mimemail_prepare() if another one does not exist, then sends the message.
+ *
+ * @param $sender
+ *   The email address or user object who is sending the message.
+ * @param $recipient
+ *   An email address or user object who is receiving the message.
+ * @param $subject
+ *   A subject line string.
+ * @param $body
+ *   The message body in HTML format.
+ * @param $plaintext
+ *   Whether to send the message as plaintext only or HTML. If set to 1, Yes
+ *   or TRUE, then the message will be sent as plaintext.
+ * @param $headers
+ *   Optional e-mail headers in a keyed array.
+ * @param $text
+ *   Optional plaintext portion of a multipart e-mail (instead of auto-generated).
+ * @param $attachments
+ *   An array of arrays which describe one or more attachments. The internal
+ *   array consists of two parts: the file's path and the file's MIME type.
+ *   The array of arrays looks something like this:
+ *   Array
+ *   (
+ *     [0] => Array
+ *       (
+ *         [filepath] => '/path/to/file.name'
+ *         [filemime] => 'mime/type'
+ *       )
+ *   )
+ * @param $mailkey
+ *   An identifier for the message.
+ * @return
+ *   An array containing the MIME encoded message, including headers and body.
+ */
发送Email的方法:
  • 你必须下载并启用mimemail模块,然后你就可以在程序中使用mimemail函数
  • 发送的电子邮件的内容中使用的CSS。我想补充的覆盖功能,这是我的template.php文件像这样:
function phptemplate_mimemail_message($body, $mailkey = null){
  return $body;
}

其他模块中使用方法:

  • 一些重要变量

global $base_url;  //系统网址

$sender = variable_get(‘site_mail’, ini_get(‘sendmail_from’)); //后台配置的邮件发送者

$title = variable_get(‘site_name’, ‘Drupal’); //系统站点名称

  • 函数调用

//pdf文件附件发送, 这里我上传的文件位于:/sites/default/files/lixiphp高级编程.pdf,注意对比自己的文件路径。

$attachments[]=array(

‘filepath’ => file_directory_path().’/lixiphp高级编程.pdf’,  //要注意的事项, 文件路径从文档根目录而不是从服务器的根。

‘filename’ => ‘lixiphp高级编程.pdf’,

‘filemime’ => ‘application/pdf’,

);

mimemail($sender,$recipient,$title,$user_body,NULL,array(),NULL,$attachments,”);

多个接收邮件人,邮件使用“,”分开,比如

$recipient = ‘admin@lixiphp.com,service@lixiphp.com,lixiphp@qq.com’; //只能使用user object和字符串变量

阅读更多>>

标签: , , ,


十一 13 2010

Drupal theming模板技巧总结第一期[原创]

Category: Drupallixiphp @ 2010-11-13 17:40:32

Drupal对于初学者来说,难点就在不知道怎么做UI,其实Drupal是很灵活的,只要你找到思想。 Drupal思想很重要,只要不断去理解Drupal的思想,不断积累,才会真正理解Drupal的灵活。工作中积累不断与大家分享,这是总结的第一期。希望有时间和大家一起分享,帮你找到Drupal的满足感!

区块PHP Code控制显示(PHP block visibility settings)

  1. Show block on specific pages:
  2. Show on every page except the listed pages.
  3. Show on only the listed pages.
  4. Show if the following PHP code returns TRUE (PHP-mode, experts only).

这里我们只讨论PHP-mode, experts only,返回值为真,则显示。返回值为假,则不显示。

<?php
if (condition) {
 return TRUE;  // block will be shown
}
 return FALSE;
?>

调用返回值。


<?php return (condition); ?>
  • 是否显示在首页 drupal_is_front_page()
  • 是否限制登录用户 user_is_anonymous()

<?php
if ( (!user_is_anonymous() && drupal_is_front_page()) ){
return FALSE;
}else{
return TRUE;
}
?>
以上代码的含义是:登录用户首页的当前区块block 不显示。

更多的研究请查看Drupal官方。

CKEditor 中使用PHP Code问题

在Drupal中安装CKEditor模块和PHP Filter模块,但是当选择PHP code作为输入格式,然后编辑器任然是CKEditor,切换到文本框,Switch to plain text editor

输入PHP Code如下:

<?php global $user;echo $user->uid; ?>

CKEditor

&lt;!–{cke_protected}%3C%3Fphp%20global%20%24user%3Becho%20%24user-%3Euid%3B%20%3F%3E–&gt;

解决方法请参考:CKEditor and GeSHi filter

如何定义分类、标签模板theme taxonomy term

/*** Adding custom PHPTemplate suggestions on taxanomy pages.
  ** @param $vars *   A sequential array of variables to pass to theme template.
  */
function phptemplate_preprocess_node(&$vars) {
  if(arg(0) == 'taxonomy'){
    $suggestions = array('node-taxonomy'); //So, node-taxonomy.tpl.php will be known afterwards.
    $vars['template_files'] = array_merge($vars['template_files'], $suggestions);
  }
}

以上函数在template.php中定义复写函数,根据地址获取第一个参数,将模板值更改。

这样模板就为:node-taxonomy.tpl.php

阅读更多>>

标签: , , , , , , , ,


十一 08 2010

工作技巧总结mysql与drupal

Category: Drupal,MySQLlixiphp @ 2010-11-08 17:23:09

记录一下两个重要的技巧,可能一不小心你就会在日常应用中遇到。

MYSQL替换字符串

mysql中的replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便。

mysql 替换函数replace() 语法:

UPDATE `table_name` SET `field_name` = replace (`field_name`,’from_str’,'to_str’) WHERE `field_name` LIKE ‘%from_str%’

说明:

table_name — 表的名字
field_name — 字段名
from_str — 需要替换的字符串
to_str — 替换成的字符串

此方法在WordPress站点移植很有用,例如更新wp-options表使用以下的SQL语句:

UPDATE `wp-options` SET `option_values` = REPLACE(`option_values`, 'www.olddomain.com', 'www.newdomain.com');

如何隐藏和删除Drupal Tab 菜单标签

当你写一个定制的模块在自己新加的内容类型时,需要添加一个menu_local_task到node/x/edit路径,但它只有在编辑自定义内容类型时显示。

添加一个菜单本地任务(TAB)很容易,但是隐瞒其他内容类型中一个tab标签菜单事实证明是徒劳无功的。而且似乎很多人遇到类似的问题。

使用hook_menu_alter或hook_menu_link_alter在隐藏或者删除tab标签是很难实现的。

在经过考虑之后,我意识到我的问题很容易通过菜单的访问权限的回调函数去解决。所以这是为特定内容类型添加、编辑和删除菜单标签menu_local_task的代码:

<?php

/***  implementation of hook_menu()*/
function mymodule_menu() {

  $items = array();

  $items['node/%node/edit/attributes'] = array(    
    'title' => 'Attributes',    
    'page callback' => 'drupal_get_form',    
    'page arguments' => array('mymodule_attributes_form', 1),    
    'access callback' => 'mymodule_attributes_access',    
    'access arguments' => array(1),    
    'weight' => 10,    
    'type' => MENU_LOCAL_TASK,
  );

  return  $items;
}

/*** Access callback for node/%node/edit/attributes.*/
function mymodule_attributes_access($node) {  
  if ($node->type != 'mymodule') {
    return FALSE;
  }
  return TRUE; 
  // TRUE or you can user user_access() permissions as well
}

?>

Drupal会严格检查用户访问没有节点的权限,如果权限不够,则不会显示TAB菜单。这样我们就可以实现对TAB菜单的删除或者隐藏操作。

上面的函数mymodule_attributes_access,还可以加入对地址栏参数的检查,回调函数的参数应该在 ‘access arguments’ => array(1, 2, …) 里设置。注意这里的 1,2 … 是指 arg(1), arg(2) …以此类推。

阅读更多>>

标签: , , , , , ,


24 2010

PHP开源CMS-Drupal做视频站点(第1版)[原创]

Category: Drupal,PHPlixiphp @ 2010-10-24 23:12:48

视频网站在web2.0时代是最常见的互联网类型,国外有Youtobe,BlipTV等,国内有优酷,土豆,酷六,网易等各大门户网站都典型的视频网站。

对于某些门户网站或综合型网站都想在CMS的基础上有自己的视频浏览页面。

问题分析

视频也可以看成一篇文章,只不过内容是视频吧了,类型和CMS差不多,但是问题就在于视频的格式,大小,传输速度等就限制了我们的开发。

在开发过程中要考虑的问题如下:

  • 是否是自己原创的视频,是否需要定制的播放还是借助第三方播放插件。
  • 管理员操纵是否合乎他们的习惯和使用是否简单、快捷。
  • 程序员需要系统的搭建,自己含有服务器、VPS还是虚拟主机。
  • 再确定好系统后,分享文件如何上传,毕竟视频不是在2M以内的普通文件,服务器对上传是否有限制。
  • 上传的视频文件是否要自动转换格式,转换后的效果,已经播放效果,包括分辨率,视频的缩略图,视频的水印处理等。

我想我的这些考虑并不是全面的,但是应该覆盖了你的大部分需求分析,接下来的问题将讲解drupal做一个视频站点。

站点目标

这里我假设我们要做个名为dummy的视频站点,它的功能和优酷、土豆网类似。

功能列表:

  • 用户可以自行在自己的个人空间上传视频
  • 管理员审核用户的视频后决定是否发布,发布后用户可以引用视频调用地址
  • 上传视频有最大文件限制
  • 上传视频可以自动转换格式为FLV,可以通过SWF文件播放
  • 转换视频为指定的分辨率,可以在水印图片到视频,视频有缩略图。
  • 管理员发布视频可以简单的发布视频

第一版 视频满足管理员操作

这篇文章主要讲解单用户内容管理系统对视频操作的站点,分为以下几个阶段:drupal基本讲解drupal模块安装Video视频设置Video视频播放器配置区块显示视频

好的,让我们真正开始我们精彩的旅程。

Drupal 基本讲解

  • 系统环境

Operating system操作系统:  Windows, Mac OS X, Linux, Unix, BSD, or Solaris
Web server服务器:  Apache 1.2 or Apache 2.x, Microsoft IIS 6 or 7, lighttpd
Database数据库:  MySQL 4.1 or MySQL 5.0, PostgreSQL 7.4
PHP编程脚本:  PHP 4.3.5. is required, but PHP 5.2.x is recommended

安装环节,请参考drupal官方网站。

drupal后台的管理界面视图如下:

drupal文章内容类型 General view of the administration page

drupal文章内容类型截图如下:

Content types video drupal文章内容类型

drupal文章分类、自由标签如下:

drupal文章分类、自由标签 Taxonomy  categories and tags image

drupal模块列表 (/admin/build/modules/) 截图如下:

drupal module 模块列表 image

大概的几个界面就讲这些,其他详细的请安装后自由的体验。

阅读更多>>

标签: , , , , , , , ,


22 2010

Godaddy 主域名绑定到子目录及管理子域名

Category: Web 2.0lixiphp @ 2010-10-22 17:06:34

Godaddy 是世界第一大域名注册商,进军主机领域以后发展迅速,据多家监测机构显示,放置在Godaddy上的网站数量已经越居第一位。

Godaddy同时提供linux主机,Windows主机,VPS以及独立主机全线主机产品,各种需求的客户在这里都可以找到适合自己的产品。美国主机评论家多次评为第一名。

Godaddy同时提供独立IP,SSL证书,帮助客户快速打造自己的电子商务网站。

Godaddy 管理子域名子目录

进入Godaddy的 Hosting Control Center > Domain Management 域名管理(https://hostingmanager.secureserver.net/DomainManagement2.aspx),见下图可以管理子域名,可以配置子域名到各个目录下。

Godaddy的 Hosting Control Center 域名管理 image

但是其添加子域名时,Subdomain不能添加www或者为空,说明这个域名管理不能管理主域名。

Godaddy Adding a subdomain to this hosting image

注意:添加域名时,可以选择其文件夹,默认是选择一个和子域名名称一样的文件夹,建议选择或者创建一个新的文件夹。

Godaddy主域名子目录问题

显然我们无法控制主域名绑定到一个子目录上去。根据Godaddy实现301跳转的思想,我决定使用.htaccess文件实现主域名绑定到子目录上去。

阅读更多>>

标签: , , , , , ,


11 2010

php算法实现二维数组转化为矩阵

Category: PHPlixiphp @ 2010-10-11 21:15:06

今天在工作中遇到一个问题,是将一个二维数组转化为一个矩阵,用php算法实现,这是在drupal的grid中碰到的,最终在同事Lake的帮助下完成。

问题描述

$rows是个二维数组,包含四行三列元素。

$rows = ([0][0], [0][1], [0][2], [1][0], [1][1], [1][2], [2][0], [2][1], [2][2], [3][0], [3][1], [3][2], )

需要转化为下图形状的矩阵,

x|x|x
x|x|x
x|x|x
x|x|x

我的需求是建立一个这样的数组,

1 | 5 | 9
2 | 6 | 10
3 | 7 | 11
4 | 8 | 12

算法设计

<?php foreach ($rows as $row_number => $columns): ?>
<?php $j = -3 ; ?>
<?php foreach ($columns as $column_number => $item): ?>
<?php $j += 4 ; ?>
<?php print ($row_number + $j); ?>
<?php endforeach; ?>
<?php endforeach; ?>

感兴趣的朋友可以试一试其他矩阵,这是一个简单的算法,如果小看php不能做算法的话,代码只能是付出执行效率作为牺牲代价。

标签: , , , ,


09 2010

排名前10的Drupal后台管理主题

Category: Web 2.0lixiphp @ 2010-10-09 15:47:12
Drupal Administration themes

第一位:RootCandy

rootcandy
RootCandy是一个三栏布局宽频或固定布局的主题,重点集中在管理部分。

  • 支持节点/添加/编辑网页
  • 重新着色,图标,滑动地区
  • 根据用户角色显示顶部导航
  • 简单的控制面板
  • 支持Rootcandy Dark子主题

第二位:Admin

admin

管理模块对标准的Drupal 6管理界面用户界面改进。它实现的一些想法是在Drupal 7的可用性改进探讨。

第三位:Seven

seven

Seven 是一个默认的Drupal 7的管理主题(由Mark博尔顿和莱萨Reichelt设计)的后台。它是的简直,这个主题作出D6兼容为那些想要开始使用它的人。如需有关主题本身的信息,请访问马克和莱萨的Drupal7的网站 在http://d7ux.org

第四位:Nerdalistic

image

将谷歌和WordPress的想法和颜色组合,目的在于一个易于使用和配置的布局。

第五位:Polpo Admin Theme

polpo
Polpo是为管理任务具体明确,简单明了而设计的,Polpo使用一个内容编辑流动的两列布局兼容大屏幕分辨率。这是通过使用的字体大小,清晰的间距和不同的颜色来辅助一般任务的使用。

阅读更多>>

标签: , , , , , , , , , ,


07 2010

将首页使用drupal开发,内容仍需完善

Category: Wo De Lifelixiphp @ 2010-10-07 20:08:14

记得曾经很想将首页用drupal来做,后来终于实现。

这里和大家一起分享一下,演示地址:http://www.lixiphp.com/,powered by drupal。

Lixi-PHP Expert  PHP Expert at Drupal,wordpress,zendframework,cakephp and ecommerce

使用的drupal module主要基于:cck和views。感谢Napoler给予的一些帮助,才使得本网站可以展示,然而在内容方面还需要进一步完善。

后台使用的主题是Garland,前台在SEO方面还没有过多的处理,但是google对drupal的更新速度快,drupal确实太强大咯!

希望与各位drupal爱好者共同交流!

标签: , , , ,


29 2010

Drupal PDF电子书全集

Category: PHPlixiphp @ 2010-09-29 00:55:22

最近正在深入研究drupal,下面的drupal学习资料是在搜集了很多网站后得到。包含了drupal从入门到精通,从主题到模块的开发,英文资料确实很强大,其中有一本为国人翻译的 drupal专业开发指南,在很多国内网站上都可以看到,在这里不妨推荐各位看原版的drupal书籍,确实值得花很多时间去研究。

Drupal PDF Ebook

Building.Online.Communities.With.Drupal,.phpBB,.And.WordPress.pdf
Building.powerful.and.robust.websites.with.Drupal.6.pdf
Cracking.Drupal.A.Drop.in.the.Bucket.pdf
drupal Core_templates_and_suggestions.pdf
drupal-6-api.chm
drupal-6-theming-cheat-sheet.pdf
Drupal.5.Themes.pdf
Drupal.5.Views.Recipes.pdf
Drupal.6.Attachment.Views.Feb.2010.pdf
Drupal.6.Content.Administration.Jun.2009.pdf
Drupal.6.Javascript.And.Jquery.pdf
Drupal.6.Panels.Cookbook.Aug.2010.pdf
Drupal.6.Panels.Cookbook.Aug.2010.rar
Drupal.6.Performance.Tips.Feb.2010.pdf
Drupal.6.Search.Engine.Optimization.Sep.2009.pdf
Drupal.6.Site.Blueprints.Aug.2009.pdf
Drupal.6.Site.Builder.Solutions.pdf
Drupal.6.Social.Networking.pdf
Drupal.Creating.Blogs,.Forums,.Portals,.And.Community.Websites.pdf
Drupal.Ecommerce.with.Ubercart.2.x.Mar.2010.pdf
Drupal.for.Education.and.E-Learning.pdf
drupal6_api_cheatsheet_0.pdf
drupal_6_themes.pdf
drupal专业开发指南.pdf
Flash.with.Drupal.May.2009.pdf
Front.End.Drupal.pdf
Learning.Drupal.6.Module.Development.pdf
Leveraging.Drupal.Getting.Your.Site.Done.Right.pdf
Packtpub.Choosing.an.Open.Source.CMS.Beginners.Guide.Apr.2009.pdf
Pro Drupal Development Second Edition.pdf
Pro.Drupal.Development.pdf
Sams.Teach.Yourself.Drupal.in.24.Hours.Nov.2009.pdf
Selling.Online.with.Drupal.eCommerce.Apr.2008.pdf
SymphonyTheme_Document_v0.1.2.pdf
Theme_Guide_Drupal_6.pdf
TopNotchThemes-basics-guide.pdf
Using Drupal.pdf

以上是我目前正在研究drupal的学习资料,均为电子资料,希望热爱drupal的朋友一起交流。

由于大家都在找 Drupal.6.Attachment.Views 这本书,所以共享出来。

附加:Drupal 6 Attachment Views 下载 ,提取码:ewl99fit,有效期31天,如果过期留下电子邮件。



标签: , ,


16 2010

drupal imagecache Internal Server Error solution

Category: PHPlixiphp @ 2010-09-16 00:10:34

The imagecache module is able to serve different versions of uploaded images. It does this in an ingenious way, making it hard to diagnose once something goes wrong. The following may help you.

How does imagecache work?

The answer is Enabling Clean URLs in Drupal.

how to enable your clean urls in drupal?

actually, if my purchase domain is www.lixiphp.com, but my drupal install in /demo directory, so clean urls is availabe http://www.lixiphp.com/demo, meanwhile, I bind a sub domain to the demo/ sub-directory, which is http://demo.lixiphp.com. Unfortunately, it is unavailable clean urls for this-domain. With this problem, I will teach you how to set it available in sub-domain, http://demo.lixiphp.com.

Firstly, finding the .htaccess file in the installation root path.

edit the .htaccess file at the 107 rows

# uncomment the following line:
RewriteBase /

So, this means that your .htaccess based dir is based on your sub-domain. Check you drupal adminstration panel.

Then enable your sub-domain Clean Urls, Congratulation!

Why you must enable you Clean Urls?

I must exactly tell you some drupal modules is based on clean urls, like ImageCahe, for example. If your clean urls is disable, you drupal project must will has Internal Server Error. As I know , Clean urls play a fatal role in drupal, otherwise you will meet a huge trouble.

If you do not know how to enable the Clean urls, Please reply me and let me know.

标签: , , , ,


Page 1 of 212