2011 年 08 月

浏览模式: 标准 | 列表 | 图文
转:用XML-RPC协议读写WordPress上的文章

转:用XML-RPC协议读写WordPress上的文章

这是一篇很小的例子,事实上网上这些例子是超多的,不过由于我是要模拟metaweblog或者是wordpress的一些操作,那我就必须要先了解很多相关的背景。
不过这里只是模拟一些发布和读取的接口,稍作了解即可。
原文来自:用XML-RPC协议读写WordPress上的文章我这里只简要的摘取一部分。

WordPress提供了XML-RPC接口使得第三方的博客写作软件(如windows live writer等)可以与之通信来发布和修改博客。我们也可以在网站上使用这个接口做一些工作,例如:在网站首页显示最新的博客、在博客之外的页面上发表博 客文章、把博客与其他内容管理系统结合,等等。

一、开启XML-RPC支持

XML-RPC协议默认是未开启的,需要到WordPress管理后台的“设置–>撰写”里的“远程发布”给XML-RPC打上勾。其说明文 字为:启用 WordPress,Movable Type,MetaWeblog和Blogger 的 XML-RPC发布协议。

二、获取接口的信息

我们查看博客首页的源代码,在head中可以发现类似这样的link项

<link title="RSD" rel="EditURI" type="application/rsd+xml" href="http://blog.bluesky.cn/xmlrpc.php?rsd" />

其中的"RSD"是“Really Simple Discovery”的意思,也就是说这是一个“简单的发现博客编辑接口”的地址。我们用浏览器直接访问这个地址就可以在其返回XML中获知博客的 ID(blogID,一般这个的值是“1”)以及它所支持的接口类型和接口地址。

三、API接口选择

WordPress提供了对Blogger API、metaWeblog API、Movable Type API以及其自身的WordPress API的支持。其中WordPress API最为丰富,提供了包括操作评论文章在内的各种各样的支持。Blogger API功能较少,基本上淘汰不用了;而metaWeblog API提供了常用的接口且参数比较简洁,用得较多一些。

四、例子代码

以下是使用Incutio的XML-RPC库和Blogger API发布文章的例子,其中IXR库也是Wordpress自身所用的库,可以在“wp-includes/class-IXR.php”找到。

<?php
$xmlrpcurl='http://blog.bluesky.cn/xmlrpc.php';
$blogid='1';
$username='admin';
$password='pass';
$postTitle='标题';
$postContent='正文内容';

require('class-IXR.php'); // /wordpress/wp-includes/class-IXR.php
$client = new IXR_Client($xmlrpcurl);

$params=array(
'',
'blog_ID'=>$blogid,
'user_login'=>$username,
'user_pass'=>$password,
'post_content'=>'' . $postContent,
'publish'=>true
);
$params=array_values($params);

$client->query("blogger.newPost",$params);
$response=$client->getResponse();

if ($response['faultCode']==0){
print 'Success';
} else {
print 'Fail:' . $response['faultString'];
}
?>
以下是用XML-RPC for PHP库和metaWeblog接口发布文章的例子。要先下载phpxmlrpc库取出其中的xmlrpc.inc来用。
<?php
include("xmlrpc.inc"); // 这里要改成xmlrpc.inc所在的路径
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';

define ('DOMAIN', 'blog.bluesky.cn'); // 博客的域名
define ('BLOGID', 1); // 博客ID,一般为1
define ('USER', 'admin'); // 博客登录的用户名
define ('PASSWORD', 'pass'); // 博客登录的密码

// 创建 xml-rpc client
$cl = new xmlrpc_client ( "/xmlrpc.php", DOMAIN, 80);

// 准备请求
$req = new xmlrpcmsg('metaWeblog.newPost');
// 逐个列出请求的参数:
$req->addParam ( new xmlrpcval ( BLOGID, 'int')); // 博客ID
$req->addParam ( new xmlrpcval ( USER, 'string' )); // 用户名
$req->addParam ( new xmlrpcval ( PASSWORD, 'string' )); // 密码
$struct = new xmlrpcval (
array (
"title" => new xmlrpcval ( '标题', 'string' ), // 标题
"description" => new xmlrpcval ( '正文内容', 'string'), // 内容
), "struct"
);
$req->addParam ( $struct );
$req->addParam ( new xmlrpcval (1, 'int')); // 立即发布

// 发送请求
$ans = $cl->send($req);

var_dump ( $ans );
?>
注意一定要加上:$GLOBALS['xmlrpc_internalencoding'] = ‘UTF-8′;这一句,否则不能正确处理中文。 另一段也是用phpxmlrpc库和metaWeblog接口发表文章的例子代码,该代码使用了返回类型为“phpvals”,这样可以直接用返回结果 的$r->val来获取文章ID号。
<?php
include("xmlrpc.inc");
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';

$c = new xmlrpc_client("/xmlrpc.php", "blog.bluesky.cn", 80);
$content['title']="标题"; //标题
$content['description']="正文内容"; //内容
$content['mt_keywords']="标签1,标签2"; //标签
$content['wp_password']=""; //文章密码,输入后显示加密
$content['categories'] = array("分类1","分类2"); //分类名
$x = new xmlrpcmsg("metaWeblog.newPost",
array(php_xmlrpc_encode("1"), //BLOG ID
php_xmlrpc_encode("admin"), //用户名
php_xmlrpc_encode("pass"), //密码
php_xmlrpc_encode($content),
php_xmlrpc_encode("1"))); //立即发表

$c->return_type = 'phpvals';
$r =$c->send($x);
if ($r->errno=="0")
echo "发表成功,文章序号为:".$r->val;
else {
echo "出错了";
print_r($r);
}
?>

以下是读取最新一篇文章的例子代码:

<?php
include("xmlrpc.inc");
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
$c = new xmlrpc_client("/xmlrpc.php", "blog.bluesky.cn", 80);

$msg = new xmlrpcmsg('metaWeblog.getRecentPosts',
array(php_xmlrpc_encode("1"),
php_xmlrpc_encode("admin"),
php_xmlrpc_encode("pass"),
php_xmlrpc_encode("1")) );
$res = $c->send($msg);
$val = $res->value();

$val->arraymem(0)->structreset();
while (list($key, $v) = $val->arraymem(0)->structeach())
{
echo "Element: $key; Type: ".$v->kindOf()."; Value:".$v->scalarval()."\n";
}
?>
原文地址:http://blog.bluesky.cn/archives/466/using-xml-rpc-protocol-to-read-and-write-articles-on-wordpress.html

RFC: MetaWeblog API

来自xmlrpc网站的资料:http://www.xmlrpc.com/metaWeblogApi
关于这些api还有一些背景资料在这里的:http://www.xmlrpc.com/stories/storyReader$2509,多看看啦。。。

Document status

This document was updated on 8/8/03, to incorporate all the RFCs related to the MetaWeblog API. The earlier version of the document is archived here. It has been reviewed by members of the MetaWeblog API mail list, and feedback has been incorporated.

On 8/24/03, I posted a last call for comments, and received several and incorporated some.

As of 8/26/03, this document is deployable. There may be changes, but they will be clearly documented, and will only clarify the spec, in no way will they change the format or protocol. It is now safe to deploy applications based on this spec.

What is the MetaWeblog API?

The MetaWeblog API (MWA) is a programming interface that allows external programs to get and set the text and attributes of weblog posts. It builds on the popular XML-RPC communication protocol, with implementations available in many popular programming environments.

Relationship between MetaWeblog API and the Blogger API

The MetaWeblog API is designed to enhance the Blogger API, which was limited in that it could only get and set the text of weblog posts. By the time MWA was introduced, in spring 2002, many weblog tools had more data stored with each post, and without an API that understood the extra data, content creation and editing tools could not access the data.

At the time of this writing, summer 2003, most popular weblog tools and editors support both the Blogger API and the MetaWeblog API.

Relationship between MetaWeblog API and RSS 2.0

The MetaWeblog API uses an XML-RPC struct to represent a weblog post. Rather than invent a new vocabulary for the metadata of a weblog post, we use the vocabulary for an item in RSS 2.0. So you can refer to a post's title, link and description; or its author, comments, enclosure, guid, etc using the already-familiar names given to those elements in RSS 2.0. Further since RSS 2.0 is extensible, so is the MetaWeblog API. We have designed conventions for representing attributes and namespaces in MWA.

Basic entry-points

There are three basic entry-points in the API:

metaWeblog.newPost (blogid, username, password, struct, publish) returns string

metaWeblog.editPost (postid, username, password, struct, publish) returns true

metaWeblog.getPost (postid, username, password) returns struct

The blogid, username, password and publish params are as in the Blogger API. newPost returns a string representation of the post id, again as defined by the Blogger API. The struct is where the juice is.

The struct

In newPost and editPost, content is not a string, as it is in the Blogger API, it's a struct. The defined members of struct are the elements of <item> in RSS 2.0, providing a rich variety of item-level metadata, with well-understood applications.

The three basic elements are title, link and description. For blogging tools that don't support titles and links, the description element holds what the Blogger API refers to as "content."

Where an element has attributes, for example, enclosure, pass a struct with sub-elements whose names match the names of the attributes according to the RSS 2.0 spec, url, length and type.

For the source element, pass a struct with sub-elements, url and name.

For categories, pass an array of strings of names of categories that the post belongs to, named categories. On the server side, it's not an error if the category doesn't exist, only record categories for ones that do exist.

In getPost, the returned value is a struct, as with the Blogger API, but it contains extra elements corresponding to the struct passed to newPost and editPost.

The server must ignore all elements that it doesn't understand.

In a call to metaWeblog.newPost or metaWeblog.editPost, if the struct contains a boolean named flNotOnHomePage, then the post does not appear on the home page, and only appears on the specified category pages.

Request and response

Here's an example of a request and a response.

Here's the post that this request is getting info about.

metaWeblog.newMediaObject

metaWeblog.newMediaObject (blogid, username, password, struct) returns struct

The blogid, username and password params are as in the Blogger API.

The struct must contain at least three elements, name, type and bits.

name is a string, it may be used to determine the name of the file that stores the object, or to display it in a list of objects. It determines how the weblog refers to the object. If the name is the same as an existing object stored in the weblog, it may replace the existing object.

type is a string, it indicates the type of the object, it's a standard MIME type, like audio/mpeg or image/jpeg or video/quicktime.

bits is a base64-encoded binary value containing the content of the object.

The struct may contain other elements, which may or may not be stored by the content management system.

If newMediaObject fails, it throws an error. If it succeeds, it returns a struct, which must contain at least one element, url, which is the url through which the object can be accessed. It must be either an FTP or HTTP url.

metaWeblog.getCategories

metaWeblog.getCategories (blogid, username, password) returns struct

The struct returned contains one struct for each category, containing the following elements: description, htmlUrl and rssUrl.

This entry-point allows editing tools to offer category-routing as a feature.

metaWeblog.getRecentPosts

metaWeblog.getRecentPosts (blogid, username, password, numberOfPosts) returns array of structs

Each struct represents a recent weblog post, containing the same information that a call to metaWeblog.getPost would return.

If numberOfPosts is 1, you get the most recent post. If it's 2 you also get the second most recent post, as the second array element. If numberOfPosts is greater than the number of posts in the weblog you get all the posts in the weblog.

Transmitting elements with attributes

The members of the struct passed in newPost and editPost come from the elements of items in RSS 2.0. The most commonly used core elements have no attributes, so it's clear how to include them in the struct. However, some elements, such as source, enclosure and category, may have attributes and a value. Here are a simple set of rules for elements that have attributes and a value. Note that these rules do not apply to enclosure and source, which are provided for specifically above.

1. If an element has attributes, then represent the element with a struct, and include the attributes as sub-elements of the struct.

2. If an element has both attributes and a value, make the element a struct, include the attributes as sub-elements, and create a sub-element for the value with the name _value. Note that this means that no element can be passed through the API that has an attribute whose name is _value.

Transmitting elements from namespaces

RSS 2.0 allows for the use of namespaces. If you wish to transmit an element that is part of a namespace include a sub-struct in the struct passed to newPost and editPost whose name is the URL that specifies the namespace. The sub-element(s) of the struct are the value(s) from the namespace that you wish to transmit.

Comments

The Blogger API provides a parameter called appkey that allows vendors to assign a key to developers so they can track and possibly limit usage of the API for certain tools. The MetaWeblog API doesn't specifically provide a parameter for an appkey. Applications that wish to transmit an appkey should add an element to the struct called appkey and set its value to the appkey that should be associated with the call.

Applications should use the fault-response scheme defined by XML-RPC. For example, trying to create, get, or edit a post without a valid username-password should generate a fault. Client applications should display the error string, as appropriate, to the user, for example, in a dialog, or in a server log.

Thanks

Thanks to Michael Bernstein for help editing this spec in summer 2003.

References

RSS 2.0; Dave Winer; 9/02.

RFC: MetaWeblog API; Dave Winer; 3/02.

Blogger API; Evan Williams; 8/01.

ManilaRPC; Andre Radke, Brent Simmons, Dave Winer; 1999.

XML-RPC; Dave Winer; 1998

资料:WordPress的四种远程XML-RPC发布协议

资料:WordPress的四种远程XML-RPC发布协议

没有什么好说的,学习一下这些资料。然后折腾中。
想用word发布博客,这些就必须要看。
原文来自:http://m2009.org/?p=998

WordPress支持四种远程发布协议,他们是 WordPress,Movable Type,MetaWeblog和Blogger 的 XML-RPC发布协议。

WordPress发布协议

WordPress 发布协议值wordpress自己的文章发布协议,他的接口最为丰富,提供了包括操作评论文章在内的各种各样的支持

WordPress发布协议文档:http://codex.wordpress.org/XML-RPC_wp

Movable Type发布协议

Movable Type,简称MT,是由位于美国加州的Six Apart公司推出的网志(blog)发布系统。它是全球最受欢迎的网志系统之一,包含多用户,评论,引用(TrackBack),主题等功能,并广泛的支持各种第三方插件。

Movable Type不仅可以应用于个人的网志系统,而且可以应用于商业、教育等领域。Movable Type于2007年12月12日正式宣布以GPLv2的协议开源。

Movable Type发布协议文档:http://www.movabletype.org/documentation/

Movable Type 文件集: http://mtbook.org/

MetaWeblog发布协议

The MetaWeblog API is an application programming interface created by software developer Dave Winer that enables weblog entries to be written, edited, and deleted using web services.

The API is implemented as an XML-RPC web service with three methods whose names describe their function: metaweblog.newPost(), metaweblog.getPost() and metaweblog.editPost(). These methods take arguments that specify the blog author’s username and password along with information related to an individual weblog entry.

The impetus for the creation of the API in 2002 was perceived limitations of the Blogger API, which serves the same purpose. Another weblog publishing API, the Atom Publishing Protocol became an IETF Internet standard (RFC 5023) in October 2007.

Many blog software applications and content mangement systems support the MetaWeblog API, as do numerous desktop clients.

MetaWeblog文档:http://www.xmlrpc.com/metaWeblogApi

Blogger发布协议

The Blogger Data API allows client applications to view and update Blogger content in the form of Google Data API feeds.

文档(墙外):http://www.blogger.com/developers/api/1_docs/

google:http://code.google.com/intl/zh-CN/apis/blogger/

比较详细的api文档

API参考文档:http://www.sixapart.com/developers/xmlrpc/

offsetParent作用范围

offsetParent作用范围

在看代码的时候看到了这个offsetParent也就顺便找了一下资料:

offsetParent从字面上理解,这是在查找元素的父亲.可实际应用中,根据浏览器他会返回不同的结果.在Opera较低版本中返回被引用元素的直接父元素,在IE中使用offsetParent有时会返回body元素,有时会返回被引用元素的父元素.为什么IE会这样.我会在下面的实例演示中解释清楚.而在FireFox中他总是返回body元素.
注意:offsetLeft与offsetTop永远是根据offsetParent来返回值,如果offsetParent返回的是父元素,那么他们就返回与父元素的偏移结果,如果offsetParent返回的是body元素,那么他们就返回与body元素的偏移结果.请根据浏览器进行测试.

然后找了一段代码进行测试:

<html>
<head>
<title>Dom:offsetParent使用</title>
</head>
<body>
<p>该网页中有4个div 他们的id值分别是a,a_1,b,b_1<br/> a包含了a_1.b包含了b_1<br/> a和b是相互独立的..下面我们分别对a_1和b_1两个子元素使用offsetParent方法.
你用IE浏览器测试,你会发现a1的运函数弹出body,而b1的运行函数返回了div,同样的两个子元素.同样的使用方法.为什么返回的结果不一样呢? 原因就是我为b1的父元素b,增加了一个宽度属性以后.他就把offsetParent看做是元素的父元素.如果不为b元素指定任何属性样式,他则返回body
而在火狐和谷歌浏览器中两次都会弹出body,不会受此影响.</p>
<div id="a">
<div id="a_1"></div>
</div>
<div id="b" style="width:200px;">
<div id="b_1"></div>
</div>
<script type="text/javascript">
function a1_offsetParent() { //测试b元素的offsetParent
var a_1 = document.getElementById("a_1");
alert(a_1.offsetParent.tagName);
}
a1_offsetParent();//运行a1测试函数
function b1_offsetParent() {
var b_1 = document.getElementById("b_1");
alert(b_1.offsetParent.tagName);
}
b1_offsetParent();//运行b1测试函数
</script>
</body>
</html>

这个时候就象上面的说明所说的,在firefox和webkit核心下两者都返回了“body”,然而:

网友hcp8706说:
在FF中使用offsetParent时不一定总返回body元素,当父元素使用css设置了定位属性时,offsetParent就会返回父元素.

于是我在div的id="b"的style里加入了position:absolute,然后再测试,果然就返回了DIV。

<div id="b" style="width:200px;position:absolute;">
<div id="b_1"></div>
</div>
<script type="text/javascript">
function b1_offsetParent() {
var b_1 = document.getElementById("b_1");
alert(b_1.offsetParent.tagName);
}
b1_offsetParent();//运行b1测试函数
</script>


学习完毕,上述的信息来自:http://www.web666.net/dom/offsetParent.html

头发是干什么用的

头发是干什么用的

隔壁的外公问儿子,五官是用来干嘛 的。
儿子一一回答,唯有一个答案让大家都捧腹大笑
1、眼睛,是用来看东西的
2、鼻子,是用来闻东西的
3、嘴巴,是用来说话的
4、耳朵,是用来听声音的
5、头发,是用来摆造型的
第五个回答让所有听到的人都捧腹大笑。果然是个很意外的回答

小家伙现在稀奇古怪的想法很多了

转:网站优化 更小的静态资源

转:网站优化 更小的静态资源

这是来自perfgeeks.com的一篇文章,介绍了一些常见的工具,还有一个脚本。
在用YII框架的时候,我用的是hightman写的一个cssmin的插件,可以直接把css和js进行合并到一个文件。对于图片,我都是把这个艰巨的任务交给前端,由他们完成,至于他们用什么样的png或者gif之类的优化软不不是我关心的了。OK,先上文章
来源网址是是:http://www.perfgeeks.com/?p=660
内容如下:

更小的静态资源(js、css、png、gif),意味着更少的网络传送时间。构建的时候,可以把这些静态资源进行压缩优化(不像gzip/deflate压缩),使之更小化。有很多相应的开源工具帮助你完成这项工作。

javascript

  • Google Closure Compiler
  • UglifyJS
  • YUI Compressor
  • ShrinkSafe
  • 其它,比如JSMIN

Node.js、jQuery1.5开始使用UglifyJS,UglifyJS压缩比YUI Compressor更小、比Google Closure Compiler更安全。尽管如此,但UglifyJS需要部署NodeJS环境,所以我们还是选择使用Google Closure Compiler

style(css)

  • CSSTidy
  • YUI Compressor
  • Yslow/Google Page Speed

CSSTidy和YUI Compressor都很棒,我们还是选择老牌的YUI Compressor,因为我们更熟悉它,它也能够满足我们的需求。

png8/gif图片

  • Optipng
  • AdvanceCOMP(advpng、advdef)
  • ImageMagic(mogrify、identify、convert)
  • Pngcrush
  • Pngout
  • gifsicle
  • jpegtran

任何大一点的网站页面都会使用到不少图片,压缩优化图片很有必要。选择什么样的图片格式,决定了怎么去压缩图片。一般而言,只要是非动画图片,我们 推荐png8,即便是颜色很少的小图片(尽管这样的图片gif有更高压缩性,但应该使用css sprites)。Pngout没有开放源码,仅能在Window NT平台使用,所以我们并不考滤使它。Pngcrush虽然很好用,但是optipng、advpng以及advdef结合使用能把图片压缩得更小,所以 我们选择optipng、advpng以及advdef压缩优化PNG图片。 Optipng压缩优化图片、而advdef则优化压缩算法。

构建脚本

发布产品的时候,我们希望构建前端资源,包括压缩优化、合并等等。构建应该尽量满足:
1.整个过程是自动的,不需要人工介入
2.所有的操作都是安全的
3.免费的命令行工具

我们这里应用bash写了一个简版的部署脚本,能够简单地应付中小型网站静态资源发布。

#!/bin/sh
#filename:build.sh
IN_FILE="/var/www.imgwell.com/themes/ocean/misc"
OUT_FILE="/var/www.imgwell.com/misc"
EXCLUDE_FILES="jquery.min.js LAB.min.js"
GOOGLE_COMPILER="/opt/build/bin/compiler.jar"
YUI_COMPRESSOR="/opt/build/bin/yuicompressor-2.4.6.jar"
OPTIPNG="/usr/local/bin/optipng -quiet -o3 "
ADVPNG="/usr/local/bin/advpng -q -z -4 "
ADVDEF="/usr/local/bin/advdef -q -z -4 "


function mt_ver_code() {
local MATRIX="23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz"
local LENGTH=12
while [ "${n:=1}" -le "$LENGTH" ]; do
local PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
let n+=1
done
echo -n ${PASS}
}

function mt_file_ext() {
local FILE=`basename -- "$1"`
echo -n "${FILE##*.}"
}

function mt_file_size() {
if [ -f "$1" ]; then
echo -n `ls -l -- "$1" |awk '{print $5}'`
else
echo -n 0
fi
}

function mt_has_exclude() {
if [ -z "$EXCLUDE_FILES" ]; then
echo -n 0
return 0
fi
echo "$EXCLUDE_FILES" |grep -q -w -- "${1}"
if [ $? -eq 0 ]; then
echo -n "1"
else
echo -n "0"
fi
}

function mt_google_compile() {
java -jar "$GOOGLE_COMPILER" --js $1 --js_output_file $2
}

function mt_yui_compressor() {
java -jar "$YUI_COMPRESSOR" $1 -o $2 --charset utf-8
}

function mt_png_opti() {
[ -f "`echo ${OPTIPNG} |awk '{print $1}'`" ] && ${OPTIPNG} "${1}"
[ -f "`echo ${ADVPNG} |awk '{print $1}'`" ] && ${ADVPNG} "${1}"
[ -f "`echo ${ADVDEF} |awk '{print $1}'`" ] && ${ADVDEF} "${1}"
}

function __main__() {
[ -d "$IN_FILE" ] || exit 1
local VER_CODE=`mt_ver_code`
local FILE_STATUS="!"
mkdir -p "${OUT_FILE}/${VER_CODE}"

for f in `ls -1 "$IN_FILE"`; do
if [ -d "${IN_FILE}/${f}" ] ; then
continue
fi

local HAS_EXCLUDE=`mt_has_exclude "${f}"`
local FILE_SRC_SIZE=`mt_file_size "${IN_FILE}/${f}"`

if [ "`mt_file_ext "${f}"`" = "js" -a "$HAS_EXCLUDE" = "0" ]; then
mt_google_compile "${IN_FILE}/${f}" "${OUT_FILE}/${VER_CODE}/${f}"
FILE_STATUS="G"
elif [ "`mt_file_ext "${f}"`" = "css" -a "$HAS_EXCLUDE" = "0" ]; then
mt_yui_compressor "${IN_FILE}/${f}" "${OUT_FILE}/${VER_CODE}/${f}"
FILE_STATUS="Y"
elif [ "`mt_file_ext "${f}"`" = "png" -a "$HAS_EXCLUDE" = "0" ]; then
cp "${IN_FILE}/${f}" "${OUT_FILE}/${VER_CODE}"
[ -f "${OUT_FILE}/${VER_CODE}/${f}" ] && {
mt_png_opti "${OUT_FILE}/${VER_CODE}/${f}"
FILE_STATUS='O'
}
else
cp "${IN_FILE}/${f}" "${OUT_FILE}/${VER_CODE}"
if [ $? -eq 0 ]; then
FILE_STATUS="-"
else
FILE_STATUS="D"
fi
fi

local FILE_DST_SIZE=`mt_file_size "${OUT_FILE}/${VER_CODE}/${f}"`
echo "${FILE_STATUS} ${HAS_EXCLUDE} ${f} ${FILE_SRC_SIZE}/${FILE_DST_SIZE}"
done
echo "===========/" $VER_CODE "\=========="
}

__main__

执行结果如下

[root@www-avatar misc]# ./build.sh
O 0 6N9FQPpTHCy.png 820/258
Y 0 base.css 40171/35530
O 0 FSEB6oLTK3I.png 10362/10362
- 0 GsNJNwuI-UM.gif 522/522
O 0 heart.png 921/807
O 0 IJYgcESal33.png 5771/5771
O 0 _IKHHfAgFQe.png 2635/2302
G 0 jquery.elastic.js 4988/1665
- 1 jquery.min.js 85260/85260
G 0 jquery.ui.dialog.js 10074/5274
G 0 jquery.ui.pview.js 4565/2878
- 1 LAB.min.js 5537/5537
O 0 lFahQXTaTNO.png 90/90
G 0 mutfa.js 36958/21777
O 0 nCItFQafRu8.png 452/288
O 0 p13yZ069LVL.png 792/219
- 0 plupload.flash.swf 18537/18537
G 0 plupload.full.js 48277/46682
Y 0 position.css 7737/7440
O 0 star.png 3292/283
G 0 stars.js 6333/2622
Y 0 ui_plugin.css 12794/12079
G 0 up.js 6230/3991
- 0 uVR6w3wRHEJ.gif 54/54
O 0 WSQ2wnhSG-F.png 245/229
- 0 _ZWZupdaAgS.gif 827/827
===========/ LruQcmx4Zi84 \==========

总结

1.UglifyJS压缩比YUI Compressor更小,比Google Closure Compiler更安全。不想冒险,还是应该选择UglifyJS。若想最小化,可以选择Google Closure Compiler
2.YUI Compressor压缩css文件。但CSSTidy也很不错
3.optipng -o3 *.png |advpng -z -4 *.png |advdef -z -4 *.png 将最大化压缩优化png图片
4.网页尽量使用png格式图片,并且压缩优化它,使之最优

-------------------------------

纠结,原文中的代码是有配色的,但是COPY过来就没有配色了,而自带的配色没有bash的配色。所以。。。将就点看了,或者看原文吧:http://www.perfgeeks.com/?p=660

10大最适合编程的字体推荐下载,让代码看起来更美更舒服!

10大最适合编程的字体推荐下载,让代码看起来更美更舒服!


我是因为看了netbeans的字体配置后,才用上了Consolas字体。我现在用的是phpstorm,而他也是基于jre的啦。于是我现在把jre里的字体配置文件复制出来。然后更新一更新就复制过去。保证所有的IDE(用jre的)字体一样。当然也好看。。。
正如文中所说的,大家用的最多的都应该是Courier New啦。写PHP的大多会用editplus,默认字体就是这个,我用这个5、6年。直到換成netbeans后,才觉得果然consolas更圆滑,看起来更舒服,而且字体也可以稍放大一点不会感觉不适。
因为我在用editplus的时候,如果字体放大一点,会看的很不适(因为我用的是笔记本,屏幕小,字体大后看的不舒服。。。)
好吧,你们还是去看文章吧,说的十种字体是:
10. Courier
9. Andale Mono
8. Monaco
7. Profont
6. Monofur
5. Proggy
4. Droid Sans Mono
3. Deja Vu Sans Mono
2. Consolas + 中文雅黑混合版
1. Inconsolata
看上去那个Inconsolata不错,因为很细,不过,已经适合Consolas了,顺便说一下,其实netbeans默认的字体就是couriernew+宋体。因为它是基于jre的了啦。你看一下font.propeties文件就知道了

原文请看:http://www.iplaysoft.com/top10-programming-fonts.html

郁闷,又在纠结swfupload的302问题了

郁闷,又在纠结swfupload的302问题了

这是一个非常让人郁闷的问题。问题也知道根源在哪里,但TMD就是纠结。
因为是SWF,你懂的,有些包抓不到的。但不搞又不行,准备用smartsniff来抓数据看了。

其实就是一个session的问题,但还没有彻底搞定,真烦人。
yii框架中应用swfupload还是有点纠结的(其实以前都没有问题,不知道什么时候,突然间就开始有这个BUG了。。。)

仔细排查了一下,其实,大家都知道,session原本就是用来处理登录这种玩意的。果然排查后发现,新开的上传进程之所以是302,就是因为跳转到登录页面去了。晶啊。每次都是这个原因,我靠

NSLog 输出格式

NSLog 输出格式

NSLog是IOS上面常用的做记录的方式,感觉有点象是php中的printf,因为常用,所以就记录了一下。
%@ 对象
• %d, %i 整数
• %u 无符整形
• %f 浮点/双字
• %x, %X 二进制整数
• %o 八进制整数
• %zu size_t
• %p 指针
• %e 浮点/双字 (科学计算)
• %g 浮点/双字
• %s C 字符串
• %.*s Pascal字符串
• %c 字符
• %C unichar
• %lld 64位长整数(long long)
• %llu 无符64位长整数
• %Lf 64位双字

反正纠结纠结就当printf了。也就@用的最多一点吧

测试insertAdjacentElement

测试insertAdjacentElement

和insertAdjacentHtml等方法类似,只是一个插对象,一个插具体内容,其实都一样啦。
介绍:
语法:
oElement = object . insertAdjacentElement ( sWhere , oElement )
参数:
oElement : 必选项。对象(Element)。要插入到 object 邻近的对象。
sWhere : 必选项。字符串(String)。beforeBegin | afterBegin | beforeEnd | afterEnd beforeBegin : 将 oElement 插到 object 的开始标签之前。
afterBegin : 将 oElement 插到 object 的开始标签之后。但是在 object 的所有原有内容之前。
beforeEnd : 将 oElement 插到 object 的结束标签之前。但是在 object 的所有原有内容之后。
afterEnd : 将 oElement 插到 object 的结束标签之后。
返回值:
oElement : 对象(Element)。返回插入的对象的引用。
说明:
将 oElement 依据 object 定位插入文档结构。
当文档正在载入时,不可以尝试此方法。必须在 onload 事件触发以后。
假如你尝试插入一个已经在文档结构中存在定位的对象,该对象将被移动到你指定的插入位置,而不会有新对象被创建。 【这个功能好啊。不会创建出同名元素等】
测试代码:

<script>
var i_nowheight = 250;
function rdl_doApply(e) {
with (document.all("oSelect1")) var sParam1 = options[selectedIndex].value;
with (document.all("oSelect2")) var sParam2 = options[selectedIndex].value;
var oNewNode = document.createElement(sParam1);
oList.insertAdjacentElement(sParam2, oNewNode);
oNewNode.innerText = sParam2
i_nowheight += 30;
window.resizeTo(360, i_nowheight);
}
</script>
<div id=oCode>
<ul id=oList>
<li>列表项目1
<li>列表项目2
</ul>
</div>
<table height=56>
<tr>
<td><select style="width:100px;" id=oSelect1>
<option value="button" selected>button</option>
<option value="b">b</option>
</select></td>
<td><select style="width:100px;" id=oSelect2>
<option value="beforeBegin" selected>beforeBegin</option>
<option value="afterBegin">afterBegin</option>
<option value="beforeEnd">beforeEnd</option>
<option value="afterEnd">afterEnd</option>
</select></td>
<td><input type=button value=" 插入 " onclick="rdl_doApply()"></td>
</tr>
</table>