Archive of published articles on July, 2007

Back home

Project Babel分析(1)

29/07/2007
  1. 对地址的重定向

    在分析具体代码前需要先简单讲一下Project Babel对apache服务器的配置,本来一篇讲php项目的文章似乎与服务器端技术无关,但是在Project Babel这个项目里大量使用了apache的重定向技术,把动态的地址静态化.使用的原因我想基本有两吧:一个是基于SEO的考虑,一般搜索引擎对静态的地址比较友好,其次是防止恶意的用户直接对URL的操作.打开\apache\htaccess\.htaccess的文件可以看到下面的代码

    RewriteRule ^$ /babel.php?m=home [L]
    RewriteRule ^([0-9]+)$ /babel_mobile.php?m=home&p=$1 [L]
    RewriteRule ^index.html$ /babel.php?m=home [L]
    RewriteRule ^hot.html$ /babel.php?m=hot [L]
    RewriteRule ^home/style/shuffle.html$ /babel.php?m=home&style=shuffle [L]
    RewriteRule ^home/style/remix.html$ /babel.php?m=home&style=remix [L]
    RewriteRule ^home/style/shuffle$ /babel.php?m=home&style=shuffle [L]
    RewriteRule ^home/style/remix$ /babel.php?m=home&style=remix [L]
    RewriteRule ^home/style/remix/([a-zA-Z0-9\-]+)$ /babel.php?m=home&style=remix&go=$1 [L]
    RewriteRule ^remix/([a-zA-Z0-9\-]+)$ /babel.php?m=home&style=remix&go=$1 [L]
    (略…)

    比如这里前部分RewriteRule ^index.html$ /babel.php?m=home [L]的意思就是把index.html重定向到/babel.php?m=home.但是如果你对下面的([0-9]+)之类的东西一头雾水,那就需要补一下正则表达式的知识了.OK,知道了这点,就可以进入实际代码的分析了

  2. 基本流程

    用惯了discuz!之类的程序的朋友可能第一次打开会傻眼,为什么没有index.php文件任何程序都有入口,那Project Babel的入口是哪里呢.这里要注意的是第一Livid写的安装知道已经告诉我们要把DocumentRoot指向htdocs目录,这里是打开网页时的根目录.但是还是不见index.php啊,这里要回到重写上面说的重定向了注意到RewriteRule ^$ /babel.php?m=home [L]了么,这里就是把主页(^$间为空)重定向到了/babel.php?m=home这个网址.这里运用了get方式传递m值为home,换句话说就是在/babel.php这个文件中$_GET['m']的值为’home’.

    if (isset($_GET['m'])) {
    $m = strtolower(trim($_GET['m']));
    } else {
    $m = ‘home’;
    }

    define(‘__PAGE__’, $m);

    这段代码在确定了$_GET['m']值已被定义的前提下把去掉空格的并且转换为小写赋值给$m,否则把’home’赋值给$m,然后再用其赋值常量__PAGE__.
    接下来”$p = &new Page();”,新建了一个Page()对象$p,这个对象可以说是整个Project Babel的灵魂,一般灵魂之类的东西都是比较玄乎的所以打算在讲到的时候再对其中的方法进行分析.
    总结下Project Babel的流程,就是先重定向为php可以读懂的代码,然后通过$_GET[]取出,然后通过Page类生成Page了,好了,下面很大部分应该就是Page类的分析和运用了.

No Comments

27/07/2007

No Comments

“I Got a Crush…On Obama” By Obama Girl

27/07/2007

在Youtube上搜索民主党黑人总统候选人obama,访问量最高的不是他的参选演说,而是一首这段时间很火的Obama Girl的一首”I Got a Crush…On Obama(暗恋奥巴马)”,当然对这位Obama Girl有着不少非议,但是who care?-当然care的人也不是没有,中国对娱乐新闻较真儿的不是也一大票,不过这就没劲了是吧.重要的是beautiful girl,beautiful song!权当是看厌政治秀的时的放松,或者反讽,什么都可以啦. Lyrics: Barack Obama: I want to thank all of you for your time, your suggestions, your encouragement, and your prayers. And I look forward to continuing our conversation in the weeks and months to come. Obama Girl: Hey B, it’s me. If you’re there, pick up. I was just watching you on C-SPAN. [Sigh] Anyway, call me back. You seem to float onto the floor Democratic Convention 2004 I never wanted anybody more Than I want you So I put down my Kerry sign Knew I had to make you mine So black and sexy, you’re so fine ‘Cause I’ve got a crush on Obama I cannot wait, ’til 2008 Baby you’re the best candidate I like it when you get hard On Hillary in debate Why don’t you pick up your phone? ‘Cause I’ve got a crush on Obama I cannot wait, ’til 2008 Baby you’re the best candidate Of the new oval office You’ll get your head of state I can’t leave you alone ‘Cause I’ve got a crush on Obama You’re into border security Let’s break this border between you and me Universal healthcare reform It makes me warm You tell the truth unlike the right You can love but you can fight You can Barack me tonight I’ve got a crush on Obama I cannot wait, ’til 2008 Baby you’re the best candidate I like it when you get hard On Hillary in debate Why don’t you pick up your phone? ‘Cause I’ve got a crush on Obama I cannot wait, ’til 2008 Baby you’re the best candidate Of the new oval office You’ll get your head of state I can’t leave you alone ‘Cause I’ve got a crush on Obama B to the A to the R-A-C-K-O-B-A-M-A (Barack Obama) [8x) ‘Cause I’ve got a crush on Obama

No Comments

排斥和迎合间的选择

27/07/2007

其实左右翼在运用新媒体的积极性上有着比较明显的区别.五天前民主党的八位总统候选人通过回应选民通过Youtube对各种问题的回应,对各项问题展开了辩论.Youtube和CNN准备趁热邀请共和党候选人也以此形式来那么下-草根媒体的纵向覆盖加上传统媒体的横向覆盖当然是对双方都是有利的,无奈只有目前只有两位同意参加(Ron PaulJohn McCain),看吧,conservative还真conservative呢~
还不止,典型的右派媒体Fox这段时间也被网民呛口水,Bill O’Reilly在他的节目把DailyKos称作3K党,这个美国订阅人数最多的政治blog的读者当然感到不满.
从netroot兴起,到政治人物纷纷开博,新媒体的趋势看来不是那么容易阻挡的了的.

No Comments