Friday, 3 September 2010

create flash(swf) file using PHP libming

My boss ask me to make a flash website, something like twinkle star. Since we don't have the Adobe Flash software so I think there should be some alternative. After google it, spend a day to search and learn some alternative, finally I choose Ming.

The Ming has support for PHP and it called libming. It make swf(flash) file using PHP. I learned PHP before so it is easy for me.

My server is running Debian Lenny 5.0. The lastest libming version is 0.4.3. In Debian 5.0 libming is 0.3.0 and in Ubuntu 10.04 the libming is 0.4.3.
I don't what to install any unstable package in the Debian server so I install a Ubuntu client.

After install ubuntu, I only install some PHP packages :

$sudo apt-get install php-cli php-common php5-ming

and others necessary packages will be installed automatically. php-cli is command line interface, that means we can run php file in console mode, not in web server.

This is the star.png file with transparency background:






Example ONE :
This php script creates a very simple static swf file. It place a star.png file on movieclips only.
<?php
Ming_useSWFVersion(5); // set flash version 5
$png= new SWFBitmap(file_get_contents("star.png","r"));
$m = new SWFMovie();
$m->add($png);
$m->setDimension(143, 143); // the flash dimension
$m->setBackground(0, 0, 0); // background color is black since star is white
$m->setRate(12.0);
$m->setFrames(20);
header('Content-type: application/x-shockwave-flash');
$m->save("static.swf",9); // save to file, compression rate: 1 - minimun , 9 - maximum
?>

Save the file as static.php In console, type
$php static.php

then it will create a static.swf file at same directory.

If you have a web server installed, you may see the result on browser. At last line, change
$m->save("static.swf",9);
to
$m->output(); // to screen

Let's the server ip is 192.168.1.1. In browser, type http://192.168.1.1/static.php, then the flash file will show on screen. It is a static flash, like a picture display on screen.

To make the star twinkle, we need some transition effect : fade in then fade out so that it look like twinkle.

Here is some tutorial for transition effect,
http://www.opaque.net/ming/tutorial/index9.html

To use transition effect, you need to download the file flashdot.tag or lashdot.zip, extract it(there are 5 files) and copy 2 files : infuncs.php and outfuncs.php.

In infuncs.php you have to comment out the line 8, like this :
// $i->moveTo(600,30);

Example TWO :
It has fade in then fade out effect :
<?php
Ming_useSWFVersion(5); // set flash version 5
include('infuncs.php');
include('outfuncs.php');
$png= new SWFBitmap(file_get_contents("star.png","r"));
$m = new SWFMovie();
$instance = fadein($m, $png);
fadeout($m, $png, $instance);
$m->setDimension(143, 143); // the flash dimension
$m->setBackground(0, 0, 0); // black color since star is white
$m->setRate(12.0);
$m->setFrames(20);
header('Content-type: application/x-shockwave-flash');
$m->save("twinkle.swf",9); // save to file, compression rate: 1 - minimun , 9 - maximum
?>


Save the file as twinkle.php. In console, type
$php twinkle.php

It made a twinkle.swf flash file.

This is the swf file :



Ming core library is under the LGPL license. Ming's command line ActionScript compiler (makeswf) is distributed under the GPL license.

That means, it is free.

Wednesday, 11 August 2010

make bootable CD in win32

Usually we use mkisofs to make bootable CD in Linux. There is also mkisofs win32 package :

http://www.student.tugraz.at/thomas.plank/index_en.html

Download 3 zip files, save into d:\cdrtools folder and uncompress all files.
- cdrtools-xxx-win32-bin.zip
- dlls.zip
- DLL version 1.7.5

I use grub4DOS as boot loader, download it at http://sourceforge.net/projects/grub4dos/files/
Get the grub4dos-0.4.4.zip and uncompress. I will save the zip file into d:\grub4dos folder.

At DOS console, type

D:\cdrtools>copy d:\grub4dos\grlder
D:\cdrtools>mkisofs -R -b grldr -no-emul-boot -boot-load-size 4 -o grldr.iso .
Setting input-charset to 'UTF-8' from locale.
mkisofs: './grldr.iso' is the archive. Not dumped.
Size of boot image is 4 sectors -> No emulation
Total translation table size: 2048
Total rockridge attributes bytes: 5027
Total directory bytes: 6144
Path table size(bytes): 34
Max brk space used 30000
4910 extents written (9 MB)

Caution : The last character of mkisofs command IS "."

Output file is grldr.iso. Burn the grldr.iso file into CD. Finished.

Monday, 2 August 2010

Debian 5 Lenny NFS

Just setup a NFS server on Debian Lenny, then mount the nfs folder and got error message :

support@client03:~$ sudo mount -t nfs 192.168.0.9:/media/HD /media/iso
mount.nfs: 192.168.0.9:/media/HD failed, reason given by server: Permission denied

Usually the problem is file /etc/exports, /etc/hosts.allow and /etc/hosts.deny

For file /etc/exports, usually many people say I can do like this to share the folder for while subnet :
/media/HD 192.168.0.0/24 (ro)

But it doesn't work.

In Debian Lenny, I have to make it as below. It solved the "Permission denied" problem.
/media/HD 192.168.0.0/255.255.255.0 (ro)

Saturday, 24 July 2010

校園O嘴事件簿 - 作者華容道



這書是說有關於校園內外發生事情, 主⻆大多是學生。 家長們只能在家內觀察自己子女,在家外便一無所知。讀過這書, 或多或少可了解時下學生行為和心態, 家長們亦可多些了解自己子女。

作者華容道是我舊同學, 他第一次出書, 期代有第二集、第三集、....第N集。

Thursday, 22 July 2010

由繁體中文 utf8 檔案轉為簡體中文 utf8 檔案

由 繁體中文 utf8 -> BIG5 ->GB -> 簡體中文 utf8
$ iconv -f utf8 -t big5 note.tw.utf8 > note.big5
$ iconv -f big5 -t gb2312 note.big5 > note.gb
$ iconv -f gb2312 -t utf8 note.gb > note.cn.utf8

可用pipe簡化 為一 command :
$ iconv -f utf8 -t big5 note.tw.utf8 | \
> iconv -f big5 -t gb2312 | \
> iconv -f gb2312 -t utf8 > note.cn.utf8

參考 :
http://samuelololol.blogspot.com/2009/11/mplayer-iconv.html


最簡單方法 :
$ cconv -f UTF8-TW -t UTF8-CN note.tw.utf8

cconv 是很新的程式, 但很好用,希望它繼續發展, 令翻譯工作更加方便。

它的homepage :
http://code.google.com/p/cconv/

Friday, 9 July 2010

Joomla SEO (二) : 404

網頁顯示404有很多原因, 例如輸入錯誤網址。

有二種方法解決Joomla 404 問題 :
1. 安裝 extension
2. 改 Joomla code

1. Joomla extension :
http://extensions.joomla.org/extensions/site-management/sef
這些 extension 是幫助你的site在SEO 做得更好, 解決404是功能之一。

各extension比較, 一目了然 :
http://www.alledia.com/blog/seo/joomla-15-seo-extension-comparison/

最有名是 sh404SEF, 但是收費的。

2. 改 Joomla code

其實網頁顯示404都有二種error message :
I.
中間紅色box 和顯示404 - Component not found

II.
Not Found
The requested URL /xxx was not found on this server.

這是Joomla official tutorial
http://docs.joomla.org/Tutorial:Create_a_Custom_404_Error_Page

如果看不明, 可以跟我方法, 我是用JA_Puity template

解決 I) 問題 :
1. 複製檔案 由 /templates/system/error.php 去 /templates/ja_purity/error.php
2. 修改檔案 error.php :

在這行之下(約第14行)
defined( '_JEXEC' ) or die( 'Restricted access' );
加入

if (($this->error->code) == '404') {
header('Location: index.php');
exit;
}

儲存


解決 II) 問題 :
在website目錄最上層新加檔案 .htaccess

.htaccess 內容 :
ErrorDocument 404 /index.php


完成後每次user打錯網址, 都會自動轉到首頁。

Wednesday, 7 July 2010

Joomla SEO : 改 page title

幫朋友做完了website, backend 是Joomla v1.5。 現在要優化它, 第一步要做就是Search Engine Optimization,SEO, 這 topic 一直很hit。

我要每一page title 都加上公司名稱, (即在browser最頂那一行) ,這功能對於 SEO 是重要的。但不知可解, 在Joomla就是沒有項功能。

通常有二種方法解決Joomla 問題 :
1. 安裝 extension (component/plugins)
2. 改 Joomla code

1. 安裝 extension 是最快捷方法, 功能多, 而且一定成功。在 Joomla Extension -> Site Management->SEO &Metadata, 有很多好用的extension :
http://extensions.joomla.org/extensions/site-management/seo-a-metadata

如只想改page title , 可以選擇 :
Title Manager Plugin
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/3521

Website Name PluginLanguage
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/3352

從安裝到完成, 不須五分鐘。


2. 改 Joomla code是很麻煩的, 又不一定成功。

這是英文教學 :
http://www.howtojoomla.net/2008060586/how-tos/templates/how-to-display-your-page-title-in-your-template-joomla-15

這是中文教學 :
http://www.hksilicon.com/kb/articles/648/1/Joomla-15----lttitlegt/Page1.html

但他們方法都有一個小問題, 是發生在 home page上, 如果你的公司名稱是"美好公司" , 而在front page又設定顯示"美好公司", home page title 會顯示 :

美好公司 - 美好公司


解決方法很簡單, 這是我的 code :


<?php

$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();

$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename'); // get site name

if ($mytitle == $sitename) // check same title and sitename
$mydoc->setTitle($sitename);
else
$mydoc->setTitle($mytitle.' - '.$sitename);

?>